K8s Timezon KST 변경 방법

작성자 이경미 수정일 2023-01-26 16:30

#podman bug, #podman, #timezon, #KST, #UTC

오류 메세지 혹은 현상
  • sodaflow 기반의 제품에서 backend server 인 sodaflow-app, gitlab, notebook 은 KST 로 생성되어야 하지만 UTC 로 생성되는 현상 발생 


원인 
  • 현재 Yaml 파일에서 HOST 의 timezon 정보를 컨테이너 볼륨 마운트로 설정합니다. 
    이 때, 적용된 localtime 이 Docker 환경에서는 동작하지만 CRI-O/Podman 환경에서 정상적으로 적용되지 않은 것으로 확인됩니다. 


  1. 동작방식
    yaml 에서 host 의 timezon 정보를 컨테이너 볼륨 마운트로 설정합니다. 
    volumeMounts:
    - name: time
      mountPath: /etc/localtime:ro
    
    volumes:
    - name: time
      hostPath:
      path: /etc/localtime

    위의 설정이 CRI-O/Podman 에서는 미적용된 것으로 확인 

  2. 버그 확인
    Podman 의 run 명령어를 사용하여 컨테이너를 생성했을 때 KST 로 timezon 이 설정된 것을 확인하였습니다. 
    podman run -it -v /etc/localtime:/etc/localtime:ro docker.io/library/busybox /bin/sh
    
    / # date
    Mon Oct 24 15:22:12 KST 2022
    / # mount |grep localtime
    /dev/mapper/rhel_master-root on /etc/localtime type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
    / #

    하지만 yaml 을 통해 kubectl 명령어를 실행하는 경우 적용되지 않는 것을 확인하였습니다.  
    $ vi busybox.yaml
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: default-timezone
    spec:
      containers:
      - image: docker.io/library/busybox
        name: busybox
        args:
        - sleep
        - "100000"
        volumeMounts:
          - name: time
            mountPath: /etc/localtime:ro
      volumes:
        - name: time
          hostPath:
            path: /etc/localtime
    
    > Pod 실행 후 컨테이너 내부에서 확인해 보면 Podman 과 생성된 mount point 가 다름.
    
    / # date
    Mon Oct 24 09:39:24 UTC 2022
    / # mount |grep localtime
    /dev/mapper/rhel_worker-root on /etc/localtime:ro type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)



문제 해결


컨테이너 생성 YAML에 ro(readonly) 옵션 지정 방식을 제거하고 readOnly 옵션을 추가하여 생성하도록 합니다. 


  • 문제 해결 방법 제시

timezone 정상 호환 OS : RHEL 7.x , Ubuntu 18.04 , Ubuntu 20.04

문제 발생 Pod : Nexus, GitLab (gitlab server, gitlab redis), Sodaflow-app


    1.  yaml 파일 수정 

pod 배포를 위한 statefulset yaml 또는 deployment yaml 에서 작업을 수행합니다. 

cd <Setup Root>/setup/<원하는 pod 설치 파일 위치>


문제가 발생하는 pod 의 yaml 파일에서 다음을 수정합니다. 

1️⃣ 기존 yaml 파일 

예시 ) nexus -> 이외의 pod 도 동일하게 적용합니다. 

# Source: nexus/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: devainexus
  labels:
    app: devainexus
    chart: "nexus-3.0.0"
    release: "devainexus"
    heritage: "Tiller"
spec:
  selector:
    matchLabels:
      app: devainexus
  serviceName: devainexus
  replicas: 1
  template:
    metadata:
      labels:
        app: devainexus
    spec:
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 50
            preference:
              matchExpressions:
                - key: sodaflow/sodaflow-master-area
                  operator: In
                  values:
                    - "true"
#      imagePullSecrets:
#        - name: regsecret
      containers:
        - name: devainexus
          image: "spsd.docker.io:15001/nexus3:3.29.2"
          imagePullPolicy: "IfNotPresent"
          resources:
            requests:
              cpu: 4000m
          ports:
            - containerPort: 8081
            - containerPort: 5001
          volumeMounts:
            - name: data
              mountPath: /nexus-data
              subPath: "nexus"
            - name: time
              mountPath: /etc/localtime:ro
#      nodeSelector:
#        sodaflow-master-area: "true"
      restartPolicy: Always
      ## hostPath directory 생성후 chown -R 200 /docker-mounts 해야 함
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: nexus-data-volume
        - name: time
          hostPath:
            path: /etc/localtime


2️⃣ yaml 파일 수정 

spec > template > spec > containers > volumeMounts (pod 에 따라 다를 수 있습니다.)

# 수정 전
            - name: time
              mountPath: /etc/localtime:ro

#  수정 후
             - name: time
              mountPath: /etc/localtime
              readOnly: true


2.  yaml 파일 재배포

수정한 timezon 을 적용하기 위해서는 pod 를 재시작하는 작업이 필요합니다. 

주의 : pvc 는 재시작하지 않습니다.  

kubectl delete -f install_nexus.yaml
kubectl apply -f install_nexus.yaml



다음 1-2 번 작업을 해당하는 pod 에 적용합니다. 

nexus, GitLab (gitlab server, gitlab redis), Sodaflow-app


마무리

  • 해당 작업동안에는 pod 를 재시작해야 하므로 제품을 사용할 수 없습니다. 


아티클이 유용했나요?

훌륭합니다!

피드백을 제공해 주셔서 감사합니다.

도움이 되지 못해 죄송합니다!

피드백을 제공해 주셔서 감사합니다.

아티클을 개선할 수 있는 방법을 알려주세요!

최소 하나의 이유를 선택하세요
CAPTCHA 확인이 필요합니다.

피드백 전송

소중한 의견을 수렴하여 아티클을 개선하도록 노력하겠습니다.

02-558-8300