How to patch statefulset on kubernetes cluster and set imagePullPolicy How to patch statefulset on kubernetes cluster and set imagePullPolicy kubernetes kubernetes

How to patch statefulset on kubernetes cluster and set imagePullPolicy


In addition to @Colwins answer, you should also add mandatory key name into container spec, otherwise you'll get does not contain declared merge key: name

So, you kubectl command should look like:

kubectl patch statefulset my-set -p '{"spec": {"template": {"spec":{"containers":[{"name":"nginx","imagePullPolicy":"Never"}]}}}}'


I think you are missing the template key in your command

kubectl patch statefulset my-set -p '{"spec": {"template": {"spec":{"containers":[{"name": "xxxxxxx", "imagePullPolicy":"IfNotPresent"}]}}}}'

The stateful set yaml looks something like this

apiVersion: apps/v1kind: StatefulSetmetadata:  name: webspec:  serviceName: "nginx"  replicas: 2  selector:    matchLabels:      app: nginx  template:    metadata:      labels:        app: nginx    spec:      containers:      - name: nginx        image: k8s.gcr.io/nginx-slim:0.8        ports:        - containerPort: 80          name: web        volumeMounts:        - name: www          mountPath: /usr/share/nginx/html  volumeClaimTemplates:  - metadata:      name: www    spec:      accessModes: [ "ReadWriteOnce" ]      resources:        requests:          storage: 1Gi

So the path to the containers field is

spec >> template >> spec >> containers