الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

kustomize

Change Kubernetes YAML per environment (dev, test, prod) without templates — base plus overlays.

المستوى
خدمة DevSecOps
المجموعة
الحاويات و Kubernetes
يحتاج root
لا
الحزمة
kustomize

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

Kustomize starts from a base (plain YAML) and applies overlays: change the namespace, image tag, replicas, labels, or patch any field. Nothing is copied by hand, and the output is plain YAML. It is built into kubectl (kubectl apply -k, kubectl kustomize) and into Argo CD and Flux.

Each folder has a kustomization.yaml that lists resources and changes.

طريقة الكتابة

kustomize build DIR
kubectl apply -k DIR
kubectl kustomize DIR

الأجزاء الرئيسية

kustomization.yaml fields

resources
Files or folders to include (also remote Git URLs).
namespace
Put everything in this namespace.
images
Change image names and tags.
replicas
Change replica counts.
patches
Strategic-merge or JSON patches for any field.
labels / commonAnnotations
Add labels / annotations to all objects.
namePrefix / nameSuffix
Change object names.
configMapGenerator / secretGenerator
Make ConfigMaps/Secrets from files (with a hash suffix).
components
Re-usable optional parts.

الخيارات 5

الأكثر استخدامًا

Commands

build DIR
Print the final YAML.
edit set image NAME=NEW:TAG
Change the image in kustomization.yaml (CI).
edit add resource FILE
Add a resource.
create --autodetect
Create a kustomization.yaml from files.
--enable-helm
Allow helmCharts in build.

أمثلة 10

$ مستخدم عادي# بصلاحية root (أو مع sudo)

  1. 1The folder layout

    tree shop
    shop/
    ├── base/
    │   ├── deployment.yaml
    │   ├── service.yaml
    │   └── kustomization.yaml
    └── overlays/
        ├── dev/kustomization.yaml
        └── prod/kustomization.yaml
  2. 2The base

    cat shop/base/kustomization.yaml
    resources:
      - deployment.yaml
      - service.yaml
    labels:
      - pairs: { app: shop }
  3. 3A prod overlay

    cat shop/overlays/prod/kustomization.yaml
    resources: [../../base]
    namespace: shop-prod
    images:
      - name: ghcr.io/s0sta/shop
        newTag: 1.4.0
    replicas:
      - name: shop
        count: 3
    patches:
      - target: { kind: Deployment, name: shop }
        patch: |-
          - op: add
            path: /spec/template/spec/containers/0/resources
            value: { limits: { memory: 512Mi, cpu: 500m } }
  4. 4See and apply the result

    kustomize build shop/overlays/prod | less
    kubectl diff -k shop/overlays/prod
    kubectl apply -k shop/overlays/prod
  5. 5Change the image tag in CI

    cd shop/overlays/prod && kustomize edit set image ghcr.io/s0sta/shop=ghcr.io/s0sta/shop:1.5.0
    git commit -am "shop 1.5.0 to prod" && git push
  6. 6Make a ConfigMap from a file

    cat shop/base/kustomization.yaml
    configMapGenerator:
      - name: shop-config
        files: [app.properties]

    The name gets a hash; pods restart by themselves when the file changes.

  7. 7Scan the final YAML

    kustomize build shop/overlays/prod > prod.yaml && trivy config prod.yaml
  8. 8Use a remote base from Git

    cat kustomization.yaml
    resources:
      - https://github.com/s0sta/platform//apps/shop/base?ref=v1.4.0
  9. 9Add a label and a name prefix to everything

    cat overlays/dev/kustomization.yaml
    resources: [../../base]
    namePrefix: dev-
    labels:
      - pairs: { env: dev }
  10. 10Patch with a small YAML file

    cat overlays/prod/probe.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata: { name: shop }
    spec:
      template:
        spec:
          containers:
            - name: shop
              readinessProbe: { httpGet: { path: /health, port: 8080 } }
    kustomize edit add patch --path probe.yaml

انتبه

  • secretGenerator with real values in Git is not safe; encrypt with SOPS or use External Secrets.
  • The kubectl built-in kustomize can be older than the standalone one.

الملفات

kustomization.yaml
The file in every base and overlay folder.

نصائح للحفظ

  • Use Helm for third-party apps and Kustomize for your own apps — or Kustomize on top of a rendered chart.

رموز الخروج

0Success.
1Error.