k8s去掉managedFields的简洁编排文件

下载yq,使用yq截取我们需要的编排文件点击下载yq

下载yq后,拷贝到/usr/local/bin下,例如cp yq_linux_amd64 /usr/local/bin/yq && chmod +x /usr/local/bin/yq

将下面内容添加到~/.bashrc

neat () {
  yq eval 'del(
    .metadata.managedFields,
    .metadata.resourceVersion,
    .metadata.selfLink,
    .metadata.creationTimestamp,
    .metadata.ownerReferences,
    .metadata.uid,
    .spec.strategy,
    .spec.revisionHistoryLimit,
    .spec.template.spec.containers[].terminationMessagePath,
    .spec.template.spec.containers[].terminationMessagePolicy,
    .status)' -
}

neatv () {
  s=.spec.template.spec$1
  yq eval $s 
}

执行source ~/.bashrc

测试neat

[root@k8s-master1 ~]# kubectl get deploy nginx-static -o yaml |neat
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  generation: 3
  labels:
    name: nginx-static
  name: nginx-static
  namespace: default
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: nginx-static
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        name: nginx-static
    spec:
      containers:
        - image: nginx:latest
          imagePullPolicy: Always
          name: nginx-static
          ports:
            - containerPort: 80
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /etc/localtime
              name: vol-localtime
              readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - hostPath:
            path: /etc/localtime
            type: ""
          name: vol-localtime

测试neatv

[root@k8s-master1 ~]# kubectl get deploy nginx-static -o yaml |neatv
containers:
  - image: nginx:latest
    imagePullPolicy: Always
    name: nginx-static
    ports:
      - containerPort: 80
        protocol: TCP
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
      - mountPath: /etc/localtime
        name: vol-localtime
        readOnly: true
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
  - hostPath:
      path: /etc/localtime
      type: ""
    name: vol-localtime

[root@k8s-master1 ~]# kubectl get deploy nginx-static -o yaml |neatv .containers[]
image: nginx:latest
imagePullPolicy: Always
name: nginx-static
ports:
  - containerPort: 80
    protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
  - mountPath: /etc/localtime
    name: vol-localtime
    readOnly: true
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值