我有一个这样的部署:
apiVersion: apps/v1
kind: Deployment
spec:
template:
volumeMounts:
- mountPath: /home
name: john-webos-vol
subPath: home
- mountPath: /pkg
name: john-vol
readOnly: true
subPath: school
Run Code Online (Sandbox Code Playgroud)
我想使用命令更改部署kubectl patch,因此它具有以下volumeMounts内容PodTemplate:
目标.yaml:
apiVersion: apps/v1
kind: Deployment
spec:
template:
volumeMounts:
- mountPath: /home
name: john-webos-vol
subPath: home
Run Code Online (Sandbox Code Playgroud)
我使用了下面的命令,但它不起作用。
kubectl patch deployment sample --patch "$(cat target.yaml)"
Run Code Online (Sandbox Code Playgroud)
谁能给我一些建议吗?
你不能用 来做到这一点kubectl patch。您在问题中所做的补丁称为strategic merge patch. 该补丁无法替换内容,而使用此补丁您只能添加内容。
就像您最初有一个container但podspec需要添加另一个一样container。您可以使用patch此处添加另一个container. 但如果您有两个container并且需要删除一个,则无法使用此类补丁来执行此操作。
如果你想这样做,patch你需要使用retainKeys. 参考号
让我解释一下如何以另一种简单的方式做到这一点。假设您已在 test.yaml 下面应用了
kubectl apply -f test.yaml
测试.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
volumeMounts:
- mountPath: /home
name: john-webos-vol
subPath: home
- mountPath: /pkg
name: john-vol
readOnly: true
subPath: school
volumes:
- name: john-webos-vol
emptyDir: {}
- name: john-vol
emptyDir: {}
Run Code Online (Sandbox Code Playgroud)
现在你需要更新这个。更新后的target.yaml将删除volume之一。
目标.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
volumeMounts:
- mountPath: /pkg
name: john-vol
readOnly: true
subPath: school
volumes:
- name: john-vol
emptyDir: {}
Run Code Online (Sandbox Code Playgroud)
你可以使用:
kubectl apply -f target.yaml
Run Code Online (Sandbox Code Playgroud)
这将使用新配置更新您的部署
| 归档时间: |
|
| 查看次数: |
3893 次 |
| 最近记录: |