环境
- kubernetes 1.20.6
- Spring Boot 2.5.1
目标
示例
deploy.yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
name: busyBox
spec:
selector:
matchLabels:
app: busyBox
template:
Metadata:
labels:
app: busyBox
spec:
containers:
- name: busyBox
image: busyBox:1.31.0
command: ["/bin/sh", "-c", "sleep 3600"]
livenessProbe:
exec:
command: ["sh", "-c", "date"]
修改前查看
[root@master ~]# kubectl get deployments.apps busyBox -o yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
name: busyBox
namespace: default
resourceVersion: "1933810"
uid: cdf95c81-469f-4d40-99e5-baf1ed2d2187
spec:
progressDeadlineseconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: busyBox
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
Metadata:
creationTimestamp: null
labels:
app: busyBox
spec:
containers:
- command:
- /bin/sh
- -c
- sleep 3600
image: busyBox:1.31.0
imagePullPolicy: IfNotPresent
livenessProbe:
exec:
command:
- sh
- -c
- date
failureThreshold: 3
periodSeconds: 10
successthreshold: 1
timeoutSeconds: 1
...
使用命令删除字段
[root@master ~]# kubectl patch deployment busyBox --type json \
-p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
deployment.apps/busyBox patched
修改后查看
...
template:
Metadata:
creationTimestamp: null
labels:
app: busyBox
spec:
containers:
- command:
- /bin/sh
- -c
- sleep 3600
image: busyBox:1.31.0
imagePullPolicy: IfNotPresent
name: busyBox
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
...
总结
介绍了通过命令的方式,删除 k8s 资源中存在的字段。
附录
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。