user890234
user890234

Reputation: 995

kubernetes from a running pod, get only required elements via -o yaml

Generally in the kubernetes we can create definition files. for non-running and running pods, namespaces, deployments etc. If we generate yaml file for non running and non existing pods it create required defination file. However, if we have to get the defination file from running pod it also generates lots tags of live environment.

How to get only required elements while we generate yaml defination from a running pod

Is there any way if we can avoid getting below details after we generate pod yaml file from a running pod

For example if we see that after running below command it also generates lot of not required elements.

k get po nginxs14 -n=devs14 -o yaml>pod1.yaml

like:

metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","kind":"Pod","metadata":{"annotations":{},"creationTimestamp":null,"labels":{"run":"nginx"},"name":"nginxs14","namespace":"devs14"},"
  creationTimestamp: "2021-04-24T11:09:56Z"
  labels:
    run: nginx
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:kubectl.kubernetes.io/last-applied-configuration: {}
        f:labels:
          .: {}
          f:run: {}
      f:spec:
        f:containers:
          k:{"name":"nginx"}:
            .: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:ports:
              .: {}
              k:{"containerPort":9080,"protocol":"TCP"}:
                .: {}
                f:containerPort: {}
                f:protocol: {}
            f:readinessProbe:
              .: {}
              f:failureThreshold: {}
              f:httpGet:
                .: {}
                f:path: {}
                f:port: {}
                f:scheme: {}
              f:periodSeconds: {}
              f:successThreshold: {}
              f:timeoutSeconds: {}
            f:resources: {}
            f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:terminationGracePeriodSeconds: {}
    manager: kubectl-client-side-apply
    operation: Update
    time: "2021-04-24T11:09:56Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          k:{"type":"ContainersReady"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
          k:{"type":"Initialized"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{"type":"Ready"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:message: {}
            f:reason: {}
            f:status: {}
            f:type: {}
        f:containerStatuses: {}
        f:hostIP: {}
        f:phase: {}
        f:podIP: {}
        f:podIPs:
          .: {}

Upvotes: 1

Views: 1066

Answers (1)

Jonas
Jonas

Reputation: 129075

after running below command it also generates lot of not required elements

A large part of the problem you describe is the managedFields:. I agree this is very verbose and mostly annoying output.

However, this is now fixed. If you upgrade to kubectl version 1.21+ this is not shown as default. Now you need to add --show-managed-fields to show these fields.

Upvotes: 3

Related Questions