How to update Service Account of a deployment that is running

I have created a deployment and a service Account for the purposes of this demo. next we will update the running deployment.

Jacksparrow:~ babatundeolu-isa$ kubectl get deploy
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx     2         2         2            2           7s
Jacksparrow:~ babatundeolu-isa$ kubectl get sa
NAME      SECRETS   AGE
default   1         23h
hello     1         6m
apiVersion: v1
  kind: Pod
  metadata:
    creationTimestamp: 2018-08-08T17:35:47Z
    generateName: nginx-65899c769f-
    labels:
      pod-template-hash: "2145573259"
      run: nginx
    name: nginx-65899c769f-wgrcm
    namespace: default
    ownerReferences:
    - apiVersion: extensions/v1beta1
      blockOwnerDeletion: true
      controller: true
      kind: ReplicaSet
      name: nginx-65899c769f
      uid: 11acd5ce-9b2a-11e8-be52-025000000001
    resourceVersion: "55566"
    selfLink: /api/v1/namespaces/default/pods/nginx-65899c769f-wgrcm
    uid: 7c3aeed8-9b31-11e8-be52-025000000001
  spec:
    containers:
    - image: nginx
      imagePullPolicy: Always
      name: nginx
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
      - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
        name: default-token-brtl4
        readOnly: true
    dnsPolicy: ClusterFirst
    nodeName: docker-for-desktop
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    serviceAccount: default
    serviceAccountName: default
Jacksparrow:~ babatundeolu-isa$ kubectl set sa deployment nginx hello
deployment.apps "nginx" serviceaccount updated
apiVersion: v1
  kind: Pod
  metadata:
    creationTimestamp: 2018-08-08T17:38:45Z
    generateName: nginx-769dbc9c-
    labels:
      pod-template-hash: "32586757"
      run: nginx
    name: nginx-769dbc9c-w2mcs
    namespace: default
    ownerReferences:
    - apiVersion: extensions/v1beta1
      blockOwnerDeletion: true
      controller: true
      kind: ReplicaSet
      name: nginx-769dbc9c
      uid: e67fb09e-9b31-11e8-be52-025000000001
    resourceVersion: "55828"
    selfLink: /api/v1/namespaces/default/pods/nginx-769dbc9c-w2mcs
    uid: e685c3fc-9b31-11e8-be52-025000000001
  spec:
    containers:
    - image: nginx
      imagePullPolicy: Always
      name: nginx
      resources: {}
      terminationMessagePath: /dev/termination-log
      terminationMessagePolicy: File
      volumeMounts:
      - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
        name: hello-token-tl6f8
        readOnly: true
    dnsPolicy: ClusterFirst
    nodeName: docker-for-desktop
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    serviceAccount: hello
    serviceAccountName: hello
    terminationGracePeriodSeconds: 30

The service account has been update with hello.

Leave a Reply

Your email address will not be published. Required fields are marked *