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:

  1. Patches (Vá):

    Ví dụ:

    patchesStrategicMerge:
    - patch.yaml
    
    
  2. ConfigMap và Secret Generator:

    Ví dụ:

    configMapGenerator:
    - name: my-config
      files:
      - config.properties
    
    
  3. Images:

    Ví dụ:

    images:
    - name: nginx
      newTag: 1.21.0
    
    
  4. Namespace:

    Ví dụ:

    namespace: my-namespace
    
    
  5. Common Labels và Annotations:

    Ví dụ:

    commonLabels:
      app: myapp
    commonAnnotations:
      note: generated by kustomize
    
    
  6. Name Prefix và Suffix:

    Ví dụ:

    namePrefix: dev-
    nameSuffix: -v1
    
    
  7. Replicas:

    Ví dụ:

    replicas:
    - name: my-deployment
      count: 3
    
    
  8. Resources:

    Ví dụ:

    resources:
    - deployment.yaml
    - service.yaml
    
    
  9. Bases:

    Ví dụ:

    bases:
    - ../../base
    
    
  10. Vars:

    Ví dụ:

    vars:
    - name: SERVICE_NAME
      objref:
        kind: Service
        name: my-service
        apiVersion: v1
      fieldref:
        fieldpath: metadata.name
    
    
  11. Components:

  12. 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

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ệ.