Como extrair um YAML a partir de um Pod

Comandos:

# Crie um POD com a última versão do nginx
kubectl run nginx-yaml --image=nginx:latest --restart=Never

# Pega o yaml do Pod recém-criado
kubectl get po nginx-yaml -o yaml

Resultado:

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2022-01-10T19:07:25Z"
  labels:
    run: nginx-yaml
  name: nginx-yaml
  namespace: default
  resourceVersion: "5822"
  uid: ff93ac8b-9ddd-40bb-8ead-daecf1c2ae7c
spec:
  containers:
  - image: nginx:latest
    imagePullPolicy: Always
    name: nginx-yaml
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: default-token-zbc2s
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: kind-worker2
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-zbc2s
    secret:
      defaultMode: 420
      secretName: default-token-zbc2s
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2022-01-10T19:07:25Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2022-01-10T19:07:30Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2022-01-10T19:07:30Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2022-01-10T19:07:25Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: containerd://6fb9a17d95baba668a18f01fa7652d0c8f81ce696a0d6f07a63fadbdfa5573b1
    image: docker.io/library/nginx:latest
    imageID: docker.io/library/nginx@sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
    lastState: {}
    name: nginx-yaml
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2022-01-10T19:07:29Z"
  hostIP: 172.18.0.3
  phase: Running
  podIP: 10.244.1.7
  podIPs:
  - ip: 10.244.1.7
  qosClass: BestEffort
  startTime: "2022-01-10T19:07:25Z"

Como trocar a versão da imagem de um Pod

Comandos:

# Crie um POD com a última versão do nginx
kubectl run nginx-versao --image=nginx:latest --restart=Never

# Agora altere a versão da imagem usada no POD para 1.7.1
kubectl set image pod/nginx-versao nginx-versao=nginx:1.7.1

Teste:

kubectl describe pod nginx-versao

Resultado:

Vc vai perceber que a imagem foi atualizada e o POD foi reiniciado.

Events:
  Type    Reason     Age                From               Message
  ----    ------     ----               ----               -------
  Normal  Scheduled  92s                default-scheduler  Successfully assigned default/nginx-versao to kind-worker
  Normal  Pulling    91s                kubelet            Pulling image "nginx:latest"
  Normal  Pulled     81s                kubelet            Successfully pulled image "nginx:latest" in 9.602176844s
  Normal  Killing    48s                kubelet            Container nginx-versao definition changed, will be restarted
  Normal  Pulling    48s                kubelet            Pulling image "nginx:1.7.1"
  Normal  Pulled     26s                kubelet            Successfully pulled image "nginx:1.7.1" in 23.017299899s
  Normal  Created    25s (x2 over 81s)  kubelet            Created container nginx-versao
  Normal  Started    25s (x2 over 81s)  kubelet            Started container nginx-versao