search by tags

for the user

adventures into the land of the command line

get k8s yaml without the fluff

sometimes you want to grab some yaml to manually recreate or create something similar, but when you dew it this way

$ kubectl get deployment my-groovy-app -n groovy-app1 -o yaml

you’re gonna get a bunch of superfluous stuff like

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "13"
  creationTimestamp: 2018-10-02T12:28:29Z
  generation: 13
  labels:
    app: groovy-app
    chart: groovy-app-0.1.0
    heritage: Tiller
    release: my-groovy-app
  name: my-groovy-app
  namespace: groovy-app1
  resourceVersion: "11165279"
  selfLink: /apis/extensions/v1beta1/namespaces/my-groovy-app/deployments/groovy-app
  uid: ab250446-c63e-11e8-82d7-0a58ac1f0549
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: groovy-app
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config: e1e82121707809ce3cc1a3d7f0a7c50809619165dd152b73449aa93e2f4b896a
      creationTimestamp: null
      labels:
        app: groovy-app
        chart: groovy-app-0.1.0
        heritage: Tiller
        release: my-groovy-app
    spec:
      containers:
      - image: some.repo/groovy-app:2.2.1-dev.5.a980b816
        imagePullPolicy: Always
        name: groovy-app
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 256Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: nginx-config
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: some.repo
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 420
          name: groovy-app-proxy
        name: nginx-config
status:
  availableReplicas: 2
  conditions:
  - lastTransitionTime: 2018-10-02T12:31:24Z
    lastUpdateTime: 2018-10-02T12:31:24Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  - lastTransitionTime: 2018-10-02T12:28:30Z
    lastUpdateTime: 2018-10-15T13:03:27Z
    message: ReplicaSet "groovy-app-79cf57ff86" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  observedGeneration: 13
  readyReplicas: 2
  replicas: 2
  updatedReplicas: 2

so much fluff, like the status, selfLink, uid, resourceVersion, creationTimestamp, generation, checksum/config.

we can get it without a lot of this stuff with the export flag

$ kubectl get deployment my-groovy-app -n groovy-app1 -o yaml --export

and you’ll get it like this

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "13"
  creationTimestamp: null
  generation: 1
  labels:
    app: groovy-app
    chart: groovy-app-0.1.0
    heritage: Tiller
    release: my-groovy-app
  name: my-groovy-app
  selfLink: /apis/extensions/v1beta1/namespaces/my-groovy-app/deployments/groovy-app
spec:
  progressDeadlineSeconds: 600
  replicas: 2
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: groovy-app
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config: e1e82121707809ce3cc1a3d7f0a7c50809619165dd152b73449aa93e2f4b896a
      creationTimestamp: null
      labels:
        app: groovy-app
        chart: groovy-app-0.1.0
        heritage: Tiller
        release: my-groovy-app
    spec:
      containers:
      - image: some.repo/groovy-app:2.2.1-dev.5.a980b816
        imagePullPolicy: Always
        name: groovy-app
        resources:
          limits:
            cpu: "1"
            memory: 1Gi
          requests:
            cpu: 500m
            memory: 256Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /etc/nginx/conf.d
          name: nginx-config
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: some.repo
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 420
          name: groovy-app-proxy
        name: nginx-config
status: {}