티스토리 뷰

<출처> 

https://kubernetes.io/docs/tutorials/configuration/configure-redis-using-configmap/



이 페이지에서는 실제 현업에서 어떻게 ConifigMap 을 이용하여 Redis를 구성할 수 있는지에 대한 방법을 제시하고  ConfigMap 태스크를 이용하여 컨테이너들의 구성을 빌드해본다.


Objectives


  • ConfigMap을 생성한다.
  • ConfigMap을 이용하여 파드 명세(specification)를 생성한다.
  • 파드를 생성한다.
  • 구성들이 정확하게 적용되어졌는지 검증한다.



Before you begin


K8S 클러스터가 필요하며, 클러스터와 커뮤니케이션할 수 있도록 구성되어진 kubctl CLI 도구도 필요하다. 클러스터 준비가 안된다면, Minikube 를 이용하여 생성할 수 있다. 또는 다음 두 개의 (웹 기반  대화형 가상 터미널 환경의) K8S 실습 도구를 이용할 수 있다.



버전 확인을 위해 kubectl version 을 수행한다.




Real World Example: Configuring Redis using a ConfigMap


ConfigMap 내 저장된 데이터를 이용하여 Redis 캐쉬를 구성하기 위해 아래 절차를 따르면 된다.

먼저 examples/pods/config/redis-config 파일로부터 ConfigMap 을 생성하자:


1
2
3
4
root@zerobig-vm:~# kubectl create configmap example-redis-config --from-file=https://k8s.io/examples/pods/config/redis-config
error: error reading https://k8s.io/examples/pods/config/redis-config: no such file or directory
root@zerobig-vm:~# kubectl create configmap example-redis-config --from-file=https://kubernetes.io/examples/pods/config/redis-config
error: error reading https://kubernetes.io/examples/pods/config/redis-config: no such file or directory
cs

→ 에러 발생

(9월 29일 23시 현재, 튜토리얼 버전이 v1.11에서 v1.12로 업그레이드 되면서 위 가이드는 변경되었음을 확인하였다. 본 문서는 v1.11에서 작성 된 것이므로 참고하기 바란다.)


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
root@zerobig-vm:/home/study/k8s# wget https://kubernetes.io/examples/pods/config/redis-config
--2018-08-10 13:45:48--  https://kubernetes.io/examples/pods/config/redis-config
Resolving kubernetes.io (kubernetes.io)... 45.54.44.100
Connecting to kubernetes.io (kubernetes.io)|45.54.44.100|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43 [text/plain]
Saving to: 쁱edis-config
 
redis-config       100%[========================================================================================================================================>]      43  --.-KB/s    in 0s     
 
2018-08-10 13:45:48 (2.16 MB/s) - 쁱edis-configsaved [43/43]
 
root@zerobig-vm:/home/study/k8s# kubectl create configmap example-redis-config --from-file=redis-config
configmap/example-redis-config created
root@zerobig-vm:/home/study/k8s# kubectl get configmap example-redis-config -o yaml
apiVersion: v1
data:
  redis-config: |
    maxmemory 2mb
    maxmemory-policy allkeys-lru
kind: ConfigMap
metadata:
  creationTimestamp: 2018-08-10T04:45:58Z
  name: example-redis-config
  namespace: default
  resourceVersion: "91406"
  selfLink: /api/v1/namespaces/default/configmaps/example-redis-config
  uid: 464465cc-9c58-11e8-b0d4-080027c86c59
cs



(참고로 Minikube 상의 ConfigMaps 상태를 확인해 보면 다음과 같다.)





이제 ConfigMap 내 저장된 config 데이터를 사용하는 pod 명세서를 생성하자.

redis-pod.yaml

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
root@zerobig-vm:/home/study/k8s# vi redis-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: redis
spec:
  containers:
  - name: redis
    image: kubernetes/redis:v1
    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
cs


pod 를 생성하자.


1
2
root@zerobig-vm:/home/study/k8s# kubectl create -f redis-pod.yaml
pod/redis created
cs


이 예제에서, config  볼륨은 "/redis-master" 에 마운트 되었다.  redis.conf 라는 파일 명에 redis-config 키를 추가하기 위해서 "path" 를 이용한다. 그러므로, redis config를 위한 파일 경로는 "/redis-master/redis.conf" 다. 여기에서 redis 마스터가 config 파일을 찾게 될 것이다.

띄어진 pod 에 진입하기 위해 "kubectl exec"  명령을 수행하고 정확하게 구성이 적용되었는지를 검증하기 위해 "redis-cli" 도구를 구동시킨다:



1
2
3
4
5
6
7
8
root@zerobig-vm:/home/study/k8s# kubectl exec -it redis redis-cli
127.0.0.1:6379> CONFIG GET maxmemory
1"maxmemory"
2"2097152"
127.0.0.1:6379> CONFIG GET maxmemory-policy
1"maxmemory-policy"
2"allkeys-lru"
127.0.0.1:6379>
cs



(참고로 Minikube 상에 Redis Pod 로 들어가서 구동 상태를 확인해 보면 다음과 같이 정상적으로 구동된 것을 확인할 수 있다.)





What's next


ConfigMap 에 대해 더 알고 싶으면 여기로 이동하자.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
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
글 보관함