Common Transformers
특정 리소스의 공통 속성을 자동으로 변경해 줌으로써 반복적인 설정을 최소화할 수 있다.
모든 속성은 어느 폴더에 속해있는 지에 따라 다르게 적용된다.
- commonLabels: 모든 쿠버네티스 리소스에 공통 라벨을 자동으로 추가해준다.
- 기존 라벨이 있으면 덮어쓰지 않고 추가됨.
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
commonLabels:
environment: dev
team: backend
# 변경 결과
metadata:
labels:
environment: dev
team: backend
- namePrefix/Suffix : 모든 리소스의 이름 앞/에 특정 문자열을 자동 추가
# kustomization.yaml
name Prefix: "dev-"
# 결과
metadata:
name: dev-my-app
# kustomization.yaml
nameSuffix: "-v1"
# 결과
metadata:
name: my-app-v1
- Namespace : 모든 리소스에 공통 네임스페이스 자동 추가
# kustomization.yaml
namespace: project-tiger
- commonAnnotations: 모든 리소스에 공통 어노테이션을 추가
# kustomization.yaml
commonAnnotations:
owner: "devops"
managedBy: "kustomize"
Image Transfomer
Image Transformer를 통해 컨테이너 이미지 정보를 동적으로 변경할 수 있다.
✅ newTag를 사용하여 이미지 태그 변경
✅ newName을 사용하여 이미지 레포지토리 변경
✅ digest를 사용하여 특정 다이제스트로 이미지 고정
# kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- deployment.yaml
images:
- name: nginx # 기존 이미지 (원래 사용된 이미지) - container 이름과 상관 X
newName: myrepo/nginx-custom # 변경할 레포지토리
newTag: "1.21.0" # 변경할 태그
실습 ]
# 하기와 같이 YAML을 미리 확인 가능
controlplane ~/code ➜ kustomize build k8s/
# Warning: 'commonLabels' is deprecated. Please use 'labels' instead. Run 'kustomize edit fix' to update your Kustomization automatically.
apiVersion: v1
data:
password: example
username: root
kind: ConfigMap
metadata:
labels:
sandbox: dev
name: data-db-credentials
...
- 모든 postgres image를 mysql 로 바꾸기.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- db/
- monitoring/
- nginx/
commonLabels:
sandbox: dev
images:
- name: postgres
newName: mysql
- nginx의 Tag 바꾸기
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- nginx-depl.yaml
- nginx-service.yaml
commonAnnotations:
owner: bob@gmail.com
images:
- name: nginx
newTag: "1.23"
반응형
'Container > Kubernetes' 카테고리의 다른 글
[K8S] Kustomize Overlay/Components (0) | 2025.02.24 |
---|---|
[K8S] Kustomize Patches (0) | 2025.02.23 |
[K8S] Kustomize build (0) | 2025.02.22 |
[K8S]Kustomize (1) | 2025.02.21 |
[K8S] Upgrading a helm chart - kodekloud 실습 (0) | 2025.02.21 |