Using kubectl path to update k8s manifest without modifying the file manually

8/10/2017

I am following the sample azure file mentioned at Azure Voting App
I have a deployment file like:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: azure-vote-front
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  minReadySeconds: 5 
  template:
    metadata:
      labels:
        app: azure-vote-front
    spec:
      containers:
      - name: azure-vote-front
        image: microsoft/azure-vote-front:redis-v1
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: 250m
          limits:
            cpu: 500m
        env:
        - name: REDIS
          value: "azure-vote-back"

I want to add an imagePullSecret to this file using a CLI and tried the following patch command which isn't working as expected. Can someone let me know what is the right way to add impagePullSecret to the deployment without modifying manually?

kubectl patch deployment azure-vote-front -p '{"spec":{"template":{"spec":{"imagePullSecret":[{"name":"mykey"}]}}}}'

Error:

Error from server: json: cannot unmarshal string into Go value of type map[string]interface {}

Can you tell me what is wrong with the patch command?

-- Ranganath Govardhanagiri
kubernetes

1 Answer

8/11/2017

I'm not sure if it was merely an "example typo", or if that was quite literally your patch command, but the field is imagePullSecrets, plural (as the array contents might hint at), not imagePullSecret singular

-- mdaniel
Source: StackOverflow