下载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)