=================
== The Archive ==
=================

[그림과 실습으로 배우는 쿠버네티스 입문] 10장. 쿠버네티스 개발 워크플로 이해하기

|

cover.jpg

10.1 쿠버네티스에 배포하기

10.1.1 Push형 배포 방법: CIOps

10.1.2 Pull형 배포 방법: GitOps

CIOpsGitOps
단순하다보안 리스크에 강하다
알기 쉽다CI 와 CD 를 명확히 분리할 수 있다
구축하기 쉽다
Push 형Pull 형

이점 1: 보안 리스크를 줄일 수 있다.


이점 2: CI 와 CD 를 분리할 수 있다.



Argo CD


Spinnaker


FluxCD

10.2 쿠버네티스 매니페스트 관리

10.2.1 Helm


Helm 설치하기

1
brew install helm

Helm Chart Repository 추가하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
~ 7s
❯ helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
"prometheus-community" has been added to your repositories

~
❯ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "istio" chart repository
...Successfully got an update from the "prometheus-community" chart repository
Update Complete. ⎈Happy Helming!⎈

설치할 네임스페이스 생성하기

1
2
3
~
❯ k create namespace monitoring    
namespace/monitoring created

helm install 실행하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
~
❯ helm install kube-prometheus-stack --namespace monitoring prometheus-community/kube-prometheus-stack
NAME: kube-prometheus-stack
LAST DEPLOYED: Sun Dec 28 01:21:46 2025
NAMESPACE: monitoring
STATUS: deployed
REVISION: 1
DESCRIPTION: Install complete
NOTES:
kube-prometheus-stack has been installed. Check its status by running:
  kubectl --namespace monitoring get pods -l "release=kube-prometheus-stack"

Get Grafana 'admin' user password by running:

  kubectl --namespace monitoring get secrets kube-prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echo

Access Grafana local instance:

  export POD_NAME=$(kubectl --namespace monitoring get pod -l "app.kubernetes.io/name=grafana,app.kubernetes.io/instance=kube-prometheus-stack" -oname)
  kubectl --namespace monitoring port-forward $POD_NAME 3000

Get your grafana admin user password by running:

  kubectl get secret --namespace monitoring -l app.kubernetes.io/component=admin-secret -o jsonpath="{.items[0].data.admin-password}" | base64 --decode ; echo

Visit https://github.com/prometheus-operator/kube-prometheus for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.
1
2
3
4
5
6
7
8
9
~
❯ k get pod --namespace monitoring
NAME                                                       READY   STATUS    RESTARTS   AGE
alertmanager-kube-prometheus-stack-alertmanager-0          2/2     Running   0          4m8s
kube-prometheus-stack-grafana-54549784dc-l4pxp             3/3     Running   0          5m44s
kube-prometheus-stack-kube-state-metrics-59b9d4c6b-r926q   1/1     Running   0          5m44s
kube-prometheus-stack-operator-6c477dc56-zffbp             1/1     Running   0          5m44s
kube-prometheus-stack-prometheus-node-exporter-gdqtj       1/1     Running   0          5m44s
prometheus-kube-prometheus-stack-prometheus-0              2/2     Running   0          4m8s
1
2
3
4
~
❯ k port-forward service/kube-prometheus-stack-grafana --namespace monitoring 8080:80
Forwarding from 127.0.0.1:8080 -> 3000
Forwarding from [::1]:8080 -> 3000

0.png

1
2
3
~
❯ kubectl --namespace monitoring get secrets kube-prometheus-stack-grafana -o jsonpath="{.data.admin-password}" | base64 -d ; echo
QJ881CgO2qPgHWWZ3A8RzpEL7L1HQdSd125yR7xQ

1.png

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
~
❯ helm show values prometheus-community/kube-prometheus-stack
# Default values for kube-prometheus-stack.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

## Provide a name in place of kube-prometheus-stack for `app:` labels
##
nameOverride: ""

## Override the deployment namespace
##
namespaceOverride: ""

# ... too long ... #
1
2
grafana:
  adminPassword: secure-password

10.2.2 Jsonnet

10.2.3 자체 템플릿

10.2.4 Kustomize

10.2.5 [만들기] Kustomize로 매니페스트를 이해하기 쉽게 만들기


사전 지식

hello-server
├── base
│   ├── deployment.yaml
│   ├── kustomization.yaml
│   └── service.yaml
└── overlays
    ├── production
    │   ├── deployment.yaml
    │   └── kustomization.yaml
    └── staging
        ├── deployment.yaml
        └── kustomization.yaml

준비

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
~
❯ brew install kustomize
==> Auto-updating Homebrew...
Adjust how often this is run with `$HOMEBREW_AUTO_UPDATE_SECS` or disable with
`$HOMEBREW_NO_AUTO_UPDATE=1`. Hide these hints with `$HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> Fetching downloads for: kustomize
✔︎ Bottle Manifest kustomize (5.8.0)                  Downloaded    7.5KB/  7.5KB
✔︎ Bottle kustomize (5.8.0)                           Downloaded    6.7MB/  6.7MB
==> Pouring kustomize--5.8.0.arm64_sequoia.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/kustomize/5.8.0: 10 files, 17.5MB
==> Running `brew cleanup kustomize`...
Disable this behaviour by setting `HOMEBREW_NO_INSTALL_CLEANUP=1`.
Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`).
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions

요구사항

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-server
  labels:
    app: hello-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-server
  template:
    metadata:
      labels:
        app: hello-server
    spec:
      containers:
        - name: hello-server
          image: blux2/hello-server:1.8
          resources:
            requests:
              memory: "256Mi"
              cpu: "10m"
            limits:
              memory: "256Mi"
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 5
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: hello-server-pdb
spec:
  maxUnavailable: 10%
  selector:
    matchLabels:
      app: hello-server

매니페스트 분할하기

분리 전
chapter-10
└── hello-server.yaml

분리 후
chapter-10
├── deployment.yaml
└── pdb.yaml

파일을 base 디렉터리에 배치하기

hello-server
├── base
│   └── deployment.yaml
└── overlays
    ├── production
    │   └── pdb.yaml
    └── staging

매니페스트의 차이점을 overlays 에 배치하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-server
spec:
  replicas: 10
  template:
    spec:
      containers:
        - name: hello-server
          resources:
            requests:
              memory: "1Gi"
            limits:
              memory: "1Gi"
hello-server
├── base
│   └── deployment.yaml
└── overlays
    ├── production
    │   ├── deployment.yaml
    │   └── pdb.yaml
    └── staging

kustomization.yaml 작성하기

1
2
3
4
5
6
~/gitFolders/build-breaking-fixing-kubernetes master*
❯ cd chapter-10/kustomize/hello-server/overlays/production 

~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server/overlays/production master*
❯ kustomize build
Error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory '/Users/bossm0n5t3r/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server/overlays/production'
1
2
3
4
5
# hello-server/base/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - deployment.yaml
1
2
3
4
5
6
7
8
# hello-server/overlays/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base
  - pdb.yaml
patches:
  - path: deployment.yaml
1
2
3
4
5
# hello-server/overlays/staging/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - ../../base

kustomize build 로 파일을 빌드하고 클러스터에 적용하기

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server master* ⇡
❯ kustomize build ./overlays/staging
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hello-server
  name: hello-server
spec:
  replicas: 3
  selector:
    matchLabels:
      app: hello-server
  template:
    metadata:
      labels:
        app: hello-server
    spec:
      containers:
      - image: blux2/hello-server:1.8
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
        name: hello-server
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          limits:
            memory: 256Mi
          requests:
            cpu: 10m
            memory: 256Mi

~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server master* ⇡
❯ kustomize build ./overlays/production 
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: hello-server
  name: hello-server
spec:
  replicas: 10
  selector:
    matchLabels:
      app: hello-server
  template:
    metadata:
      labels:
        app: hello-server
    spec:
      containers:
      - image: blux2/hello-server:1.8
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 10
          periodSeconds: 5
        name: hello-server
        readinessProbe:
          httpGet:
            path: /health
            port: 8080
          initialDelaySeconds: 5
          periodSeconds: 5
        resources:
          limits:
            memory: 1Gi
          requests:
            cpu: 10m
            memory: 1Gi
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: hello-server-pdb
spec:
  maxUnavailable: 10%
  selector:
    matchLabels:
      app: hello-server
1
2
3
~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server master* ⇡
❯ kustomize build ./overlays/staging | k --namespace default apply -f -
deployment.apps/hello-server created
1
2
3
4
5
6
~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server master* ⇡
❯ k get pod --namespace default   
NAME                            READY   STATUS    RESTARTS   AGE
hello-server-655dcf956d-7bx22   1/1     Running   0          33s
hello-server-655dcf956d-jzz9b   1/1     Running   0          33s
hello-server-655dcf956d-qtqd2   1/1     Running   0          33s
1
2
3
~/gitFolders/build-breaking-fixing-kubernetes/chapter-10/kustomize/hello-server master* ⇡
❯ kustomize build ./overlays/staging | k --namespace default delete -f -
deployment.apps "hello-server" deleted from default namespace

Categories:

Tags: