Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to leverage kubectl patch deployment to update an environment variable?

I'm trying to patch a deployment, but I keep hitting deployment.extensions/velero not patched.

I've tried a few different variations of the following:

kubectl patch deployment velero -n velero -p '{"spec":{"containers":[{"env":[{"name":"AWS_CLUSTER_NAME","value":"test-cluster"}]}]}}'

My initial deployment.yaml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: velero
  labels:
    app.kubernetes.io/name: velero
    app.kubernetes.io/instance: velero
    app.kubernetes.io/managed-by: Tiller
    helm.sh/chart: velero-2.1.1
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/instance: velero
      app.kubernetes.io/name: velero
  template:
    metadata:
      labels:
        app.kubernetes.io/name: velero
        app.kubernetes.io/instance: velero
        app.kubernetes.io/managed-by: Tiller
        helm.sh/chart: velero-2.1.1
    spec:
      restartPolicy: Always
      serviceAccountName: velero-server
      containers:
        - name: velero
          image: "gcr.io/heptio-images/velero:v1.0.0"
          imagePullPolicy: IfNotPresent
          command:
            - /velero
          args:
            - server
          volumeMounts:
            - name: plugins
              mountPath: /plugins
            - name: cloud-credentials
              mountPath: /credentials
            - name: scratch
              mountPath: /scratch
          env:
            - name: AWS_SHARED_CREDENTIALS_FILE
              value: /credentials/cloud
            - name: VELERO_SCRATCH_DIR
              value: /scratch
      volumes:
        - name: cloud-credentials
          secret:
            secretName: cloud-credentials
        - name: plugins
          emptyDir: {}
        - name: scratch
          emptyDir: {}

I'm a bit stuck right now and fear I may be going about this the wrong way. Any suggestions would be much appreciated.

like image 541
nxf5025 Avatar asked Aug 22 '19 03:08

nxf5025


People also ask

How do you patch a deployment in Kubernetes?

Use a JSON merge patch to update a Deployment With a JSON merge patch, if you want to update a list, you have to specify the entire new list. And the new list completely replaces the existing list. For a comparison of JSON patch and JSON merge patch, see JSON Patch and JSON Merge Patch.

Which kubectl command can be used to do a deployment update?

You can use kubectl set to make changes to an object's image , resources (compute resource such as CPU and memory), or selector fields. The kubectl set image command updates the nginx image of the Deployment's Pods one at a time. You can use kubectl apply to update a resource by applying a new or updated configuration.


1 Answers

Apart from kubectl patch command, you can also make use of kubectl set env to update environment variable of k8s deployment.

kubectl set env deployment/velero AWS_CLUSTER_NAME=test-cluster

Hope this helps.

like image 101
mchawre Avatar answered Oct 30 '22 11:10

mchawre