๐น Kubernetes ํด๋ฌ์คํฐ ์์ฒด ๊ด๋ฆฌ(Self-managed Cluster)๋?
์ผ๋ฐ์ ์ผ๋ก Argo CD๋ ์ ํ๋ฆฌ์ผ์ด์
์ ๋ฐฐํฌํ๋ ๋ฐ ์ฌ์ฉ๋์ง๋ง,
์ด๋ฅผ ํ์ฅํ์ฌ Kubernetes ํด๋ฌ์คํฐ ์์ฒด๋ฅผ Argo CD๋ก ๊ด๋ฆฌํ ์๋ ์์ต๋๋ค.
์ฆ, ํด๋ฌ์คํฐ์ ๋คํธ์ํฌ, RBAC, ์ธํ๋ผ ๋ฆฌ์์ค, CRD(Custom Resource Definition) ๋ฑ์ GitOps ๋ฐฉ์์ผ๋ก ์ด์ํ ์ ์์ต๋๋ค.
โ Kubernetes ํด๋ฌ์คํฐ ์์ฒด ๊ด๋ฆฌ(Self-managed Cluster)์ ์ฅ์
โ GitOps ๋ฐฉ์์ผ๋ก ํด๋ฌ์คํฐ ๊ตฌ์ฑ์ ์ฝ๋๋ก ๊ด๋ฆฌ ๊ฐ๋ฅ
โ ํด๋ฌ์คํฐ ์ค์ ๋ณ๊ฒฝ ์ฌํญ์ ์๋ ๋๊ธฐํ ๋ฐ ๋ณต๊ตฌ ๊ฐ๋ฅ
โ ์ด์์๊ฐ ์ง์ ๊ฐ์
ํ์ง ์์๋ ์ธํ๋ผ ๊ตฌ์ฑ์ ์ง์์ ์ผ๋ก ์ ์ง
โ ๋ค์ค ํด๋ฌ์คํฐ ํ๊ฒฝ์์ ์ผ๊ด๋ ์ค์ ์ ์ฉ ๊ฐ๋ฅ
๐น 1. Argo CD๋ฅผ ํ์ฉํ ํด๋ฌ์คํฐ ๋ฆฌ์์ค ๊ด๋ฆฌ
Argo CD๋ฅผ ํ์ฉํ๋ฉด ๋ค์์คํ์ด์ค, ๋คํธ์ํฌ ์ ์ฑ , RBAC ์ค์ , CRD ๋ฑ ๋ค์ํ Kubernetes ํด๋ฌ์คํฐ ๋ฆฌ์์ค๋ฅผ ์๋ ๊ด๋ฆฌํ ์ ์์ต๋๋ค.
โ 1.1 ๋ค์์คํ์ด์ค ๋ฐ ๊ธฐ๋ณธ ๋ฆฌ์์ค ์๋ ์์ฑ
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: cluster-resources
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/example/repo.git
targetRevision: main
path: cluster-resources # ํด๋ฌ์คํฐ ๋ฆฌ์์ค ์ ์ ๊ฒฝ๋ก
destination:
server: https://kubernetes.default.svc
namespace: kube-system # ํด๋ฌ์คํฐ ๋ฆฌ์์ค ๋ฐฐํฌ
syncPolicy:
automated:
prune: true
selfHeal: true
โ
์ค๋ช
:
โ path: cluster-resources → Git ์ ์ฅ์ ๋ด ํด๋ฌ์คํฐ ๋ฆฌ์์ค ์ ์ ๊ฒฝ๋ก
โ namespace: kube-system → ํด๋ฌ์คํฐ ๋ฆฌ์์ค๋ kube-system ๋ค์์คํ์ด์ค์์ ๊ด๋ฆฌ
โ syncPolicy.automated → GitOps ๋ฐฉ์์ผ๋ก ์๋ ๋๊ธฐํ ๋ฐ ๋ณต๊ตฌ
โ Argo CD๋ฅผ ํ์ฉํ ํด๋ฌ์คํฐ ๋ฆฌ์์ค ๋๊ธฐํ ์คํ
argocd app sync cluster-resources
โ ์ถ๋ ฅ ์์:
Application 'cluster-resources' synchronized
๐น 2. Argo CD๋ฅผ ํ์ฉํ RBAC(Role-Based Access Control) ๊ด๋ฆฌ
Argo CD๋ฅผ ํ์ฉํ์ฌ Kubernetes RBAC ์ ์ฑ ์ ์ ์ธ์ ๋ฐฉ์์ผ๋ก ๊ด๋ฆฌํ ์ ์์ต๋๋ค.
โ 2.1 RBAC ์ ์ฑ ์ ์
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: dev-role
namespace: development
rules:
- apiGroups: [""]
resources: ["pods", "services"]
verbs: ["get", "list", "create", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: dev-rolebinding
namespace: development
subjects:
- kind: User
name: developer@example.com
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: dev-role
apiGroup: rbac.authorization.k8s.io
โ
์ค๋ช
:
โ Role → ๊ฐ๋ฐ์๊ฐ pods ๋ฐ services๋ฅผ ์์ฑ, ์กฐํ, ์ญ์ ํ ์ ์๋๋ก ์ค์
โ RoleBinding → developer@example.com ์ฌ์ฉ์๋ฅผ dev-role์ ์ฐ๊ฒฐํ์ฌ ๊ถํ ๋ถ์ฌ
โ RBAC ์ ์ฑ ์ Argo CD๋ก ์๋ ๋ฐฐํฌ
argocd app sync cluster-rbac
โ ์ถ๋ ฅ ์์:
Application 'cluster-rbac' synchronized
๐น 3. Argo CD๋ฅผ ํ์ฉํ ๋คํธ์ํฌ ์ ์ฑ (Network Policy) ๊ด๋ฆฌ
Kubernetes ํด๋ฌ์คํฐ ๋ณด์์ ๊ฐํํ๋ ค๋ฉด ๋คํธ์ํฌ ์ ์ฑ
(NetworkPolicy) ์ ์ ์ฉํด์ผ ํฉ๋๋ค.
Argo CD๋ฅผ ํ์ฉํ๋ฉด GitOps ๋ฐฉ์์ผ๋ก ๋คํธ์ํฌ ์ ์ฑ
์ ์ ์ธ์ ๋ฐฉ์์ผ๋ก ๊ด๋ฆฌํ ์ ์์ต๋๋ค.
โ 3.1 ๋คํธ์ํฌ ์ ์ฑ ์ ์
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-app-access
namespace: example
spec:
podSelector:
matchLabels:
app: example-app
policyTypes:
- Ingress
ingress:
- from:
- podSelector:
matchLabels:
role: frontend
ports:
- protocol: TCP
port: 80
โ
์ค๋ช
:
โ podSelector.matchLabels: app: example-app → ๋์ ์ ํ๋ฆฌ์ผ์ด์
์ ํ
โ ingress.from.podSelector: role: frontend → ํ๋ก ํธ์๋ Pod์์๋ง ์ ๊ทผ ํ์ฉ
โ ports: 80 → 80 ํฌํธ(TCP) ํธ๋ํฝ๋ง ํ์ฉ
โ ๋คํธ์ํฌ ์ ์ฑ ์ Argo CD๋ก ์๋ ๋ฐฐํฌ
argocd app sync cluster-network-policy
โ ์ถ๋ ฅ ์์:
Application 'cluster-network-policy' synchronized
๐น 4. Argo CD๋ฅผ ํ์ฉํ ํด๋ฌ์คํฐ CRD(Custom Resource Definition) ๊ด๋ฆฌ
Kubernetes์์ CRD(Custom Resource Definition)๋ฅผ ํ์ฉํ๋ฉด ํด๋ฌ์คํฐ๋ฅผ ํ์ฅํ์ฌ ์๋ก์ด ๋ฆฌ์์ค ์ ํ์ ์ถ๊ฐํ ์ ์์ต๋๋ค.
Argo CD๋ฅผ ํ์ฉํ๋ฉด CRD๋ฅผ ์ ์ธ์ ๋ฐฉ์์ผ๋ก ๋ฐฐํฌํ๊ณ ์ ์ง ๊ด๋ฆฌํ ์ ์์ต๋๋ค.
โ 4.1 CRD ์ ์ ์์
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: databases.example.com
spec:
group: example.com
names:
kind: Database
plural: databases
singular: database
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
engine:
type: string
version:
type: string
โ
์ค๋ช
:
โ kind: CustomResourceDefinition → ์๋ก์ด CRD ์์ฑ
โ names.kind: Database → ์๋ก์ด ๋ฆฌ์์ค ์ ํ ์ถ๊ฐ (Database)
โ properties.engine, properties.version → ๋ฐ์ดํฐ๋ฒ ์ด์ค ์์ง ๋ฐ ๋ฒ์ ํ๋ ์ ์
โ CRD๋ฅผ Argo CD๋ก ์๋ ๋ฐฐํฌ
argocd app sync cluster-crd
โ ์ถ๋ ฅ ์์:
Application 'cluster-crd' synchronized
๐น ๊ฒฐ๋ก : ์ด๋ฒ ๊ธ์์ ๋ฐฐ์ด ํต์ฌ ๋ด์ฉ ์ ๋ฆฌ
๐ข Argo CD๋ฅผ ํ์ฉํ์ฌ Kubernetes ํด๋ฌ์คํฐ ๋ฆฌ์์ค๋ฅผ ์๋ํํ ์ ์์
๐ข RBAC ๋ฐ ๋คํธ์ํฌ ์ ์ฑ
์ GitOps ๋ฐฉ์์ผ๋ก ์ ์ฉํ์ฌ ๋ณด์ ๊ฐํ ๊ฐ๋ฅ
๐ข CRD(Custom Resource Definition)๋ฅผ ํ์ฉํ์ฌ Kubernetes๋ฅผ ํ์ฅ ๊ฐ๋ฅ
๐ข ํด๋ฌ์คํฐ ์์ฒด๋ฅผ ์ฝ๋๋ก ์ ์ํ๊ณ , ๋ณ๊ฒฝ ์ฌํญ์ ์๋์ผ๋ก ๋ฐ์ ๊ฐ๋ฅ