ํด๋น ๋ฌธ์์ ์ฟ ๋ฒ๋คํฐ์ค ๋ฒ์ : v1.33
Kubernetes v1.33 ๋ฌธ์๋ ๋ ์ด์ ์ ๊ทน์ ์ผ๋ก ๊ด๋ฆฌ๋์ง ์์. ํ์ฌ ๋ณด๊ณ ์๋ ๋ฌธ์๋ ์ ์ ์ค๋ ์ท์. ์ต์ ๋ฌธ์๋ฅผ ์ํด์๋, ๋ค์์ ์ฐธ๊ณ . ์ต์ ๋ฒ์ .
์ปจํผ๊ทธ๋งต์ ์ฌ์ฉํด์ Redis ์ค์ ํ๊ธฐ
์ด ํ์ด์ง์์๋ ์ปจํผ๊ทธ๋งต(ConfigMap)์ ์ฌ์ฉํด์ Redis๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ์ค์ธ๊ณ ์์ ๋ฅผ ์ ๊ณตํ๊ณ , ์ปจํผ๊ทธ๋งต์ ์ฌ์ฉํด์ ํ๋ ์ค์ ํ๊ธฐ ํ์คํฌ๋ก ๋น๋๋ฅผ ํ๋ค.
๋ชฉ์
- Redis ์ค์ ๊ฐ์ผ๋ก ์ปจํผ๊ทธ๋งต์ ์์ฑํ๋ค.
- ์์ฑ๋ ์ปจํผ๊ทธ๋งต์ ๋ง์ดํธํ๊ณ ์ฌ์ฉํ๋ Redis ํ๋๋ฅผ ์์ฑํ๋ค.
- ์ค์ ์ด ์ ์ ์ฉ๋์๋์ง ํ์ธํ๋ค.
์์ํ๊ธฐ ์ ์
์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ๊ฐ ํ์ํ๊ณ , kubectl ์ปค๋งจ๋-๋ผ์ธ ํด์ด ํด๋ฌ์คํฐ์ ํต์ ํ ์ ์๋๋ก ์ค์ ๋์ด ์์ด์ผ ํ๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ปจํธ๋กค ํ๋ ์ธ ํธ์คํธ๊ฐ ์๋ ๋ ธ๋๊ฐ ์ ์ด๋ 2๊ฐ ํฌํจ๋ ํด๋ฌ์คํฐ์์ ์คํํ๋ ๊ฒ์ ์ถ์ฒํ๋ค. ๋ง์ฝ, ์์ง ํด๋ฌ์คํฐ๋ฅผ ๊ฐ์ง๊ณ ์์ง ์๋ค๋ฉด, minikube๋ฅผ ์ฌ์ฉํด์ ์์ฑํ๊ฑฐ๋ ๋ค์ ์ฟ ๋ฒ๋คํฐ์ค ํ๋ ์ด๊ทธ๋ผ์ด๋ ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ฒ์ ํ์ธ์ ์ํด์, ๋ค์ ์ปค๋งจ๋๋ฅผ ์คํ kubectl version
.
- ์์๋
kubectl
1.14 ์ด์ ๋ฒ์ ์์ ๋์ํ๋ค. - ์ปจํผ๊ทธ๋งต์ ์ฌ์ฉํด์ ํ๋ ์ค์ ํ๊ธฐ๋ฅผ ์ดํดํ๋ค.
์ค์ธ์ ์์ : ์ปจํผ๊ทธ๋งต์ ์ฌ์ฉํด์ Redis ์ค์ ํ๊ธฐ
์๋ ๋จ๊ณ๋ฅผ ํตํด์, ์ปจํผ๊ทธ๋งต์ ์ ์ฅ๋ ๋ฐ์ดํฐ๋ฅผ ์ฌ์ฉํ๋ Redis ์บ์๋ฅผ ์ค์ ํ๋ค.
์ฐ์ , ๋น์ด ์๋ ์ค์ ์ผ๋ก ์ปจํผ๊ทธ๋งต์ ์์ฑํ๋ค.
cat <<EOF >./example-redis-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: example-redis-config
data:
redis-config: ""
EOF
์์์ ์์ฑํ ์ปจํผ๊ทธ๋งต์ Redis ํ๋ ๋งค๋ํ์คํธ์ ํจ๊ป ์ ์ฉํ๋ค.
kubectl apply -f example-redis-config.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml
Redis ํ๋ ๋งค๋ํ์คํธ์ ๋ด์ฉ์ ๊ฒํ ํ๊ณ ๋ค์์ ์ฌํญ์ ์ผ๋์ ๋๋ค.
config
๋ผ๋ ์ด๋ฆ์ ๋ณผ๋ฅจ์spec.volumes[1]
์ ์ํด์ ์์ฑ๋๋ค.spec.volumes[1].configMap.items[0]
๋ด๋ถ์key
์path
๋config
๋ณผ๋ฅจ์redis.conf
๋ผ๋ ํ์ผ๋ช ์ผ๋ก ์ง์ ๋example-redis-config
์ปจํผ๊ทธ๋งต์redis-config
ํค๋ฅผ ๋ ธ์ถ์ํจ๋ค.- ๊ทธ๋ฆฌ๊ณ
config
๋ณผ๋ฅจ์spec.containers[0].volumeMounts[1]
์ ์ํด์/redis-master
์ ๋ง์ดํธ๋๋ค.
์ด ๋ด์ฉ์ ์์ example-redis-config
์ปจํผ๊ทธ๋งต์ data.redis-config
๋ด๋ถ ๋ฐ์ดํฐ๋ฅผ ํ๋ ์์ ์๋
/redis-master/redis.conf
ํ์ผ์ ๋ด์ฉ์ผ๋ก ๋
ธ์ถ์ํค๋ ์ํจ๊ณผ(net effect)๋ฅผ ๋ธ๋ค.
apiVersion: v1
kind: Pod
metadata:
name: redis
spec:
containers:
- name: redis
image: redis:5.0.4
command:
- redis-server
- "/redis-master/redis.conf"
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- mountPath: /redis-master
name: config
volumes:
- name: data
emptyDir: {}
- name: config
configMap:
name: example-redis-config
items:
- key: redis-config
path: redis.conf
์์ฑ๋ ์ค๋ธ์ ํธ๋ฅผ ํ์ธํ๋ค.
kubectl get pod/redis configmap/example-redis-config
๋ค์์ ๊ฒฐ๊ณผ๋ฅผ ๋ณผ ์ ์๋ค.
NAME READY STATUS RESTARTS AGE
pod/redis 1/1 Running 0 8s
NAME DATA AGE
configmap/example-redis-config 1 14s
example-redis-config
์ปจํผ๊ทธ๋งต์ redis-config
ํค๋ฅผ ๊ณต๋์ผ๋ก ๋ ๊ฒ์ ๊ธฐ์ตํ์.
kubectl describe configmap/example-redis-config
redis-config
ํค๊ฐ ๋น์ด ์๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
Name: example-redis-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
redis-config:
kubectl exec
๋ฅผ ์ฌ์ฉํ์ฌ ํ๋์ ์ ์ํ๊ณ , ํ์ฌ ์ค์ ํ์ธ์ ์ํด์ redis-cli
๋๊ตฌ๋ฅผ ์คํํ๋ค.
kubectl exec -it redis -- redis-cli
maxmemory
๋ฅผ ํ์ธํ๋ค.
127.0.0.1:6379> CONFIG GET maxmemory
๊ธฐ๋ณธ๊ฐ์ธ 0์ ๋ณผ ์ ์์ ๊ฒ์ด๋ค.
1) "maxmemory"
2) "0"
์ ์ฌํ๊ฒ, maxmemory-policy
๋ฅผ ํ์ธํ๋ค.
127.0.0.1:6379> CONFIG GET maxmemory-policy
์ด๊ฒ๋ ๊ธฐ๋ณธ๊ฐ์ธ noeviction
์ ๋ณด์ฌ์ค ๊ฒ์ด๋ค.
1) "maxmemory-policy"
2) "noeviction"
์ด์ example-redis-config
์ปจํผ๊ทธ๋งต์ ๋ช ๊ฐ์ง ์ค์ ๊ฐ์ ์ถ๊ฐํด ๋ณธ๋ค.
apiVersion: v1
kind: ConfigMap
metadata:
name: example-redis-config
data:
redis-config: |
maxmemory 2mb
maxmemory-policy allkeys-lru
๊ฐฑ์ ๋ ์ปจํผ๊ทธ๋งต์ ์ ์ฉํ๋ค.
kubectl apply -f example-redis-config.yaml
์ปจํผ๊ทธ๋งต์ด ๊ฐฑ์ ๋ ๊ฒ์ ํ์ธํ๋ค.
kubectl describe configmap/example-redis-config
๋ฐฉ๊ธ ์ถ๊ฐํ ์ค์ ๊ฐ์ ํ์ธํ ์ ์์ ๊ฒ์ด๋ค.
Name: example-redis-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
redis-config:
----
maxmemory 2mb
maxmemory-policy allkeys-lru
์ค์ ์ด ์ ์ฉ๋์๋์ง ํ์ธํ๋ ค๋ฉด, kubectl exec
๋ฅผ ํตํ redis-cli
๋ก Redis ํ๋๋ฅผ ๋ค์ ํ์ธํ๋ค.
kubectl exec -it redis -- redis-cli
maxmemory
๋ฅผ ํ์ธํ๋ค.
127.0.0.1:6379> CONFIG GET maxmemory
๊ธฐ๋ณธ๊ฐ์ธ 0์ ๋ณผ ์ ์์ ๊ฒ์ด๋ค.
1) "maxmemory"
2) "0"
์ ์ฌํ๊ฒ, maxmemory-policy
๋ ๊ธฐ๋ณธ ์ค์ ์ธ noeviction
์ ๋ณด์ฌ์ค ๊ฒ์ด๋ค.
127.0.0.1:6379> CONFIG GET maxmemory-policy
์์ ๋ช ๋ น์ ๋ค์์ ๋ฐํํ๋ค.
1) "maxmemory-policy"
2) "noeviction"
ํ๋๋ ์ฐ๊ด๋ ์ปจํผ๊ทธ๋งต์์ ๊ฐฑ์ ๋ ๊ฐ์ ์ธ์งํ๊ธฐ ์ํด์ ์ฌ์์์ด ํ์ํ๋ฏ๋ก ํด๋น ์ค์ ๊ฐ์ด ๋ณ๊ฒฝ๋์ง ์์ ์ํ์ด๋ค. ํ๋๋ฅผ ์ญ์ ํ๊ณ ๋ค์ ์์ฑํ๋ค.
kubectl delete pod redis
kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/config/redis-pod.yaml
์ด์ ๋ง์ง๋ง์ผ๋ก ์ค์ ๊ฐ์ ๋ค์ ํ์ธํด ๋ณธ๋ค.
kubectl exec -it redis -- redis-cli
maxmemory
๋ฅผ ํ์ธํ๋ค.
127.0.0.1:6379> CONFIG GET maxmemory
์ด๊ฒ์ ์ด์ ๊ฐฑ์ ๋ ๊ฐ์ธ 2097152๋ฅผ ๋ฐํํ๋ค.
1) "maxmemory"
2) "2097152"
์ ์ฌํ๊ฒ, maxmemory-policy
๋ ๊ฐฑ์ ๋์ด ์๋ค.
127.0.0.1:6379> CONFIG GET maxmemory-policy
์ด๊ฒ์ ์ํ๋ ๊ฐ์ธ allkeys-lru
๋ฅผ ๋ฐํํ๋ค.
1) "maxmemory-policy"
2) "allkeys-lru"
์์ฑ๋ ์์์ ์ญ์ ํ์ฌ ์์ ์ ์ ๋ฆฌํ๋ค.
kubectl delete pod/redis configmap/example-redis-config
๋ค์ ๋ด์ฉ
- ์ปจํผ๊ทธ๋งต ๋ฐฐ์ฐ๊ธฐ.