使用kubectl apply deployment ,指定deployment,默认更新他第一个container的镜像,并且给出了更新该container某些env的样例:
DEPLOYMENT_NAME="xxx"
NAMESPACE=XXX
xxx_ENV_VAL=xxxx
IMAGE_VERSION=V1.0
container_name="$(kubectl get deployment $DEPLOYMENT_NAME -o=jsonpath='{.spec.template.spec.containers[0].name}' -n $NAMESPACE)"
echo "container name is ${container_name}"
image_version_patch='{"spec":{"template":{"spec":{"containers":[{"name":"'${container_name}'","image":"'xxx:$IMAGE_VERSION'","env":[{"name":"xxx","value":"'${xxx_ENV_VAL}'"}]}]}}}}'
kubectl patch deployment $DEPLOYMENT_NAME-p="${image_version_patch}" -n $NAMESPACE2>&1