본문 바로가기
개발

[kubernetes] microk8s x509: certificate has expired or is not yet valid

by eun2ce 2022. 9. 23.

인증서 만료 이슈

x509: certificate has expired or is not yet valid: current time 2022-09-01T00:34:57-04:00 is before 2022-09-05T08:21:00Z

 

명령어는 본인이 설치 한 방법에 따라 조금 다를 수 있습니다.

  • snap으로 설치한 경우 microk8s.refresh-certs ( dot을 이용하여 명령어 구분 )
  • 기타 microk8s refresh-certs ( 띄어쓰기를 이용하여 명령어 구분 )

만료되지 않은 경우

아래 명령어를 이용하여 ca-path 확인

 

해당 경로로부터 인증서 갱신

eun2ce ~/$ sudo microk8s.refresh-certs
Taking a backup of the current certificates under /var/snap/microk8s/2760/var/log/ca-backup/
Creating new certificates
Signature ok
subject=/C=GB/ST=Canonical/L=Canonical/O=Canonical/OU=Canonical/CN=127.0.0.1
Getting CA Private Key
Signature ok
subject=/CN=front-proxy-client
Getting CA Private Key
1
Creating new kubeconfig file
2022-09-06T00:29:39-04:00 INFO Waiting for "snap.microk8s.daemon-cluster-agent.service" to stop.
2022-09-06T00:30:09-04:00 INFO Waiting for "snap.microk8s.daemon-containerd.service" to stop.
Stopped.
Started.



The CA certificates have been replaced. Kubernetes will restart the pods of your workloads.
Any worker nodes you may have in your cluster need to be removed and re-joined to become aware of the new CA.

 

이미 만료 된 인증서 일 경우에는

local 시간을 임시로 만료 날짜 이전으로 변경하여 갱신하면 됩니다.

timedatectl set-time "2022-08-22"

//ntp exception 이 날 경우
timedatectl set-ntp no

// 재 시도
timedatectl set-time "2022-08-22"

 

특별히 인증서를 백업할 필요는 없는 게, microk8s 같은 경우에는 refresh-certs 명령어를 실행했을 때, 기존 인증서는 ca-backup에 자동으로 백업이 되고 실패해서 이전 상태로 돌리고 싶을 경우에는 아래 명령어를 사용하면 다시 해당 인증서로 revert 시켜준다.

sudo microk8s.refresh-certs -u

 

마지막으로 갱신 된 인증서의 만료 날짜를 확인

sudo microk8s.refresh-certs -c

 

참고

https://microk8s.io/docs/command-reference#heading--microk8s-refresh-certs