k8s 批量服务挂载时区/jq 解析json
k8s 批量服务挂载时区
#!/bin/bash list=("zebra-assess-serviceworker" "zebra-assess-service") for i in ${list[@]}; do #i="zebra-assess-serviceworker" cat > time_patch.json<<END { "spec": { "template": { "spec": { "containers": [ { "name": "${i}", "volumeMounts": [ { "mountPath": "/etc/localtime", "name": "timezone" } ] } ], "volumes": [ { "hostPath": { "path": "/usr/share/zoneinfo/Asia/Shanghai", "type": "" }, "name": "timezone" } ] } } } } END kubectl -n cbf-houming patch deploy ${i} --patch "$(cat time_patch.json)" done
yaml方式
[root@node1 time_zone]# cat patch-file.yaml spec: template: spec: containers: - name: "zebra-assess-service" volumeMounts: - name: timezone mountPath: /etc/localtime volumes: - name: timezone hostPath: path: /usr/share/zoneinfo/Asia/Shanghai
kubectl -n cbf-houming patch deploy zebra-assess-service --patch "$(cat patch-file.yaml)"
jq解析json文件的值
[root@node1 time_zone]# jq .spec.template.spec.containers[0].name patch-file.json
"zebra-assess-service"