# 우선 테스트를 위한 샘플 yaml 파일 생성(주의: 들여쓰기 2칸이어야 함)
rm -f test.yaml
cat << zzz > test.yaml
contents:
- data:
id: "apple"
value: 100
name: my1
- data:
name: "lemon"
value: 200
name: my2
current: my2
zzz
# yq 로 보기
cat test.yaml | yq
# 또는
yq test.yaml
# current 값보기
cat test.yaml | yq '.current'
# contents > 0번째 원소 보기
cat test.yaml | yq '.contents.[0]'
# contents 원소들중 name == my 로 시작하는 원소들 보기
cat test.yaml | yq '.contents.[] | select(.name == "my*")'
# contents 원소들중 name == my1 인 것의 data > id 보기
cat test.yaml | yq '.contents.[] | select(.name == "my1") | .data.id
# 또는
cat test.yaml | yq '.contents.[] | select(.name == "my1").data.id
# ingress yaml 명세서 중 특정 필드 삭제
kubectl get ingress ysoftman-ing -n aaa -o yaml | yq '
del(
.metadata.annotations."argocd.argoproj.io/tracking-id",
.metadata.annotations."kubectl.kubernetes.io/last-applied-configuration",
.metadata.creationTimestamp,
.metadata.finalizers,
.metadata.generation,
.metadata.resourceVersion,
.metadata.uid,
.status
)
'
comments:
댓글 쓰기