Home > Net >  Kubectl get deployment yaml file
Kubectl get deployment yaml file

Time:06-14

I know how to list of pods for certain namespace as follows:

kubectl get pods -n mynamespace

There is one POD on the list which i am interested. I would like to be able to see what yaml deployment file was used for creation of that pod and the content of it. Moreover what would be kubectl command to edit such yaml file?

CodePudding user response:

To get the yaml file try kubectl get deploy deploymentname -o yaml To update the pod with the new yaml file first either find and edit the yaml file or copy the contents and make the changes you want to make, then run: kubectl apply -f newDeployment.yaml to update the cluster with your changes.

CodePudding user response:

To get the deployment used to generate a pod, have to look at the pod yaml or describe the pod:

kubectl get pod -n {namespace} {pod-name} -o yaml

Look for the "ownerReferences" section. This will tell you what "owns" the pod. This will likely be a ReplicaSet (which is generated by the Deployment). For example, this is my one from my canonical-service-controller-manager pod:

$ kubectl get  pod -n asm-system canonical-service-controller-manager-67c8f5fff5-dzd4t -o yaml
apiVersion: v1
kind: Pod
metadata:
  ...
  namespace: asm-system
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: ReplicaSet
    name: canonical-service-controller-manager-67c8f5fff5
    uid: 2504c96b-9ef7-45fa-b5d2-2a20f09486e1
  resourceVersion: "13507"
  uid: 54748cf7-26f8-4e8a-996a-725dbc89c66b
...

You can then find the replicaset and do the same thing. In my example, the replicaset is called "canonical-service-controller-manager-67c8f5fff5"

$ kubectl get replicaset -n asm-system canonical-service-controller-manager-67c8f5fff5 -o yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  annotations:
    ...
  generation: 1
  labels:
    ...
  name: canonical-service-controller-manager-67c8f5fff5
  namespace: asm-system
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: Deployment
    name: canonical-service-controller-manager
    uid: eafe2590-5005-492f-9673-0f02ac74a4d5
spec:
  replicas: 1
  ...

So you can see here, the deployment that created the replicaset, which in turn created my pod is canonical-service-controller-manager

So now I can get the deployment yaml using

$ kubectl get deployment -n asm-system canonical-service-controller-manager -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    ...
  creationTimestamp: "2022-06-14T06:35:58Z"
  generation: 1
  labels:
    ...
  name: canonical-service-controller-manager
  namespace: asm-system
spec:
  ...

If I wanted to edit the deployment, I can do so using this:

kubectl edit deployment -n asm-system canonical-service-controller-manager

Bear in mind, that editing the deployment will cycle all the pods in the deployment as they are all replicas.

  • Related