티스토리 뷰

Cloud/Kubernetes

initcontainer with multicommand

Jacob_baek 2021. 4. 13. 22:46

initcontainer를 사용하여 특정 volume에 데이터를 수정해야 하는 상황이 있고 이때 다수의 command line을 입력해주어야 하는 경우가 생겨 관련된 내용을 정리해보았다.

실제 initcontainer는 container가 동작되기 약 3초정도 후에 동작된것을 확인할수 있다.
즉 동시에 실행되는것은 아니고 initcontainer가 먼저 동작되고 완료된 이후 실제 서비스가 될 container가 동작되었다.
(참고로 현재 환경은 이미 image가 pull 된 상태이다.)

[root@node-003 ~]# crictl ps -a | grep openldap
c680eec173823       e41f3abfaad4c       12 minutes ago      Running             openldap                       0                   80986d8ca7d21
76aff3809cfbb       388056c9a6838       12 minutes ago      Exited              openldap-data-permission-fix   0                   80986d8ca7d21
## initcontainer
[root@node-003 ~]# crictl inspect 76aff3809cfbb | grep -E 'createdAt|finishedAt'
    "createdAt": "2021-04-13T15:22:10.415657268+09:00",
    "finishedAt": "2021-04-13T15:22:10.493547484+09:00",
## real service container
[root@node-003 ~]# crictl inspect c680eec173823 | grep -E 'createdAt|finishedAt'
    "createdAt": "2021-04-13T15:22:13.232492756+09:00",
    "finishedAt": "1970-01-01T09:00:00+09:00",

아래와 같이 initcontainer에서는 busybox를 통해 특정 command를 수행하게 만들수 있다.

      initContainers:
      - name: openldap-data-permission-fix
        image: busybox
        command: ["/bin/sh", "-c"]
        args: ["/bin/chown -R 1001:1001 /bitnami/openldap-data && /bin/cp -rf /bitnami/openldap-data/ /bitnami/openldap/"]
        volumeMounts:
        - name: openldap-data
          mountPath: /bitnami/openldap-data
      volumes:
        - name: openldap-data
          persistentVolumeClaim:
            claimName: openldap-data-pvc

여기서는 args 를 추가하여 다수의 command line을 처리할수 있도록 하였다.

NOTE
여기서 사용할 command (chown, cp 등)의 위치를 잘 선정해주어야 한다.
해당 container는 PATH가 설정되어 있지 않아 not found 로 error가 return 될수 있다.

참고사이트

'Cloud > Kubernetes' 카테고리의 다른 글

Custom domain lookup on Kubernetes  (0) 2021.05.07
Kustomize  (0) 2021.04.19
Velero  (0) 2021.04.06
ingress with subpath  (0) 2021.03.23
Cluster-API  (0) 2021.03.20
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
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
글 보관함