Skip to content
Search

Kustomize

lastmod 2025-12-24created 2023-03-0815 edits

About

Kustomize is a tool for customizing Kubernetes configurations. It has the following features for managing application configuration files.

  • Generating resources from other sources
  • Setting cross-cutting fields for resources
  • Composing and customizing collections of resources

Install

curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash

Install with winget:

winget install --id Kubernetes.kustomize -e

Usage

It is usually used by piping into the -f - option (a typical example is kubeflow):

kustomize build ./example | kubectl apply -f -

Or it can be used with the -k option:

kubtctl apply -k ./example

How to remove what was installed

# 1. 일반 리소스 삭제
kubectl delete -k . --ignore-not-found=true

# 2. 강제 삭제 (타임아웃 시)
kubectl delete -k . --grace-period=0 --force --ignore-not-found=true

Example

kustomization.yaml

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - deploy/deployment.yaml
  - deploy/service.yaml

deploy/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: inspekt-deployment
  labels:
    app: inspekt
spec:
  replicas: 1
  selector:
    matchLabels:
      app: inspekt
  template:
    metadata:
      labels:
        app: inspekt
    spec:
      containers:
        - name: inspekt
          image: premist/inspekt:latest
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: HOST_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - containerPort: 8000
          livenessProbe:
            httpGet:
              path: /
              port: 8000
            initialDelaySeconds: 3
            periodSeconds: 3

deploy/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: inspekt
  namespace: default
spec:
  ports:
  - name: http
    targetPort: 8000
    port: 80
  selector:
    app: inspekt

deploy/ingress-example.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: inspekt
spec:
  rules:
    - http:
        paths:
          - path: /
            backend:
              serviceName: inspekt
              servicePort: http

See also

Favorite site

author Zer0 sitemap