Need to understand exactly how patch works. How could I patch "imagePullPolicy" for instance. Could someone explain in simple details how patch works.
kubectl patch statefulset my-set -p '{"spec":{"containers":{"imagePullPolicy":"IfNotPresent"}}}'
This is not working what is wrong with it?
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/v1
kind: StatefulSet
metadata:
name: web
spec:
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