Kustomize cho phép tùy chỉnh các tài nguyên Kubernetes một cách linh hoạt và mạnh mẽ mà không cần sửa đổi các file YAML gốc. Dưới đây là một số cách Kustomize có thể tùy chỉnh tài nguyên Kubernetes:
Patches (Vá):
Ví dụ:
patchesStrategicMerge:
- patch.yaml
ConfigMap và Secret Generator:
Ví dụ:
configMapGenerator:
- name: my-config
files:
- config.properties
Images:
Ví dụ:
images:
- name: nginx
newTag: 1.21.0
Namespace:
Ví dụ:
namespace: my-namespace
Common Labels và Annotations:
Ví dụ:
commonLabels:
app: myapp
commonAnnotations:
note: generated by kustomize
Name Prefix và Suffix:
Ví dụ:
namePrefix: dev-
nameSuffix: -v1
Replicas:
Ví dụ:
replicas:
- name: my-deployment
count: 3
Resources:
Ví dụ:
resources:
- deployment.yaml
- service.yaml
Bases:
Ví dụ:
bases:
- ../../base
Vars:
Ví dụ:
vars:
- name: SERVICE_NAME
objref:
kind: Service
name: my-service
apiVersion: v1
fieldref:
fieldpath: metadata.name
Components:
Transformers:
Kustomize cho phép bạn tổ chức cấu hình theo layers, sử dụng bases và overlays để quản lý cấu hình cho nhiều môi trường hoặc variants khác nhau. Điều này giúp duy trì tính nhất quán và giảm thiểu sự trùng lặp trong cấu hình Kubernetes.
kind: Kustomization
là một phần quan trọng trong cấu trúc file của Kustomize. Đây là định nghĩa của file cấu hình chính mà Kustomize sử dụng để xác định cách tùy chỉnh và tổ chức các tài nguyên Kubernetes.
Khi bạn tạo một file có tên kustomization.yaml
(hoặc kustomization.yml
), bạn sẽ bắt đầu file với:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
Đây là cách để Kustomize nhận biết rằng đây là một file cấu hình Kustomization hợp lệ.