Skip to content

Instantly share code, notes, and snippets.

@r00tvvm
Forked from coresolve/patch_example.md
Created November 7, 2021 17:04
Show Gist options
  • Select an option

  • Save r00tvvm/d46abaef2a2c9d3a92d9248af2cc96ef to your computer and use it in GitHub Desktop.

Select an option

Save r00tvvm/d46abaef2a2c9d3a92d9248af2cc96ef to your computer and use it in GitHub Desktop.

Revisions

  1. @coresolve coresolve created this gist Oct 18, 2017.
    128 changes: 128 additions & 0 deletions patch_example.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,128 @@
    Start with a simple deployment:

    `kubectl run simple --image=quay.io/dcooley/simple-app:plain --replicas=3 --port=80 --labels=app=simple`

    show the yaml for this deployment:

    ```
    $ kubectl get deployment simple -o yaml --export
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    annotations:
    deployment.kubernetes.io/revision: "1"
    creationTimestamp: null
    generation: 1
    labels:
    app: simple
    name: simple
    selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/simple
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: simple
    strategy:
    rollingUpdate:
    maxSurge: 1
    maxUnavailable: 1
    type: RollingUpdate
    template:
    metadata:
    creationTimestamp: null
    labels:
    app: simple
    spec:
    containers:
    - image: quay.io/dcooley/simple-app:plain
    imagePullPolicy: IfNotPresent
    name: simple
    ports:
    - containerPort: 80
    protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    dnsPolicy: ClusterFirst
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    terminationGracePeriodSeconds: 30
    status: {}
    ```

    Show the pods with the labels:

    ```
    $ kubectl get pods -l app=simple --show-labels
    NAME READY STATUS RESTARTS AGE LABELS
    simple-1632802685-b3fff 1/1 Running 0 1m app=simple,pod-template-hash=1632802685
    simple-1632802685-cdns1 1/1 Running 0 1m app=simple,pod-template-hash=1632802685
    simple-1632802685-p2h3q 1/1 Running 0 1m app=simple,pod-template-hash=1632802685
    ```

    Make the patch:

    ```
    $ kubectl patch deployment simple --type=json -p='[{"op": "add", "path": "/spec/template/metadata/labels/this", "value": "that"}]'
    deployment "simple" patched
    ```

    Show that the pods have the new label:

    ```
    $ kubectl get pods -l app=simple --show-labels
    NAME READY STATUS RESTARTS AGE LABELS
    simple-2157335326-85pzk 1/1 Running 0 25s app=simple,pod-template-hash=2157335326,this=that
    simple-2157335326-g7jwv 1/1 Running 0 27s app=simple,pod-template-hash=2157335326,this=that
    simple-2157335326-qmcjk 1/1 Running 0 27s app=simple,pod-template-hash=2157335326,this=that
    ```

    Show the new deployment:
    ```
    $ kubectl get deployment simple -o yaml --export
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
    annotations:
    deployment.kubernetes.io/revision: "2"
    creationTimestamp: null
    generation: 1
    labels:
    app: simple
    name: simple
    selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/simple
    spec:
    replicas: 3
    selector:
    matchLabels:
    app: simple
    strategy:
    rollingUpdate:
    maxSurge: 1
    maxUnavailable: 1
    type: RollingUpdate
    template:
    metadata:
    creationTimestamp: null
    labels:
    app: simple
    this: that
    spec:
    containers:
    - image: quay.io/dcooley/simple-app:plain
    imagePullPolicy: IfNotPresent
    name: simple
    ports:
    - containerPort: 80
    protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    dnsPolicy: ClusterFirst
    restartPolicy: Always
    schedulerName: default-scheduler
    securityContext: {}
    terminationGracePeriodSeconds: 30
    status: {}
    ```