YJWANG

Kubernetes secret tls 인증서 갱신 본문

60.Cloud/80.Kubernetes

Kubernetes secret tls 인증서 갱신

왕영주 2020. 12. 3. 13:27

우선 기존 인증서의 만료일을 확인해야한다.

인증서 만료 확인


secret 확인

[root@wyj05_deploy_0 cert]# kubectl get secrets -n https test1
NAME    TYPE                DATA   AGE
test1   kubernetes.io/tls   2      11m

인증서 만료 확인

[root@wyj05_deploy_0 cert]# kubectl get secret test1 -n https -o "jsonpath={.data['tls\.crt']}" | base64 -d | openssl x509 -enddate -noout
notAfter=Nov 30 08:32:54 2021 GMT

인증서 갱신 진행


혹시 인증서 key file에 암호가 있다면 해지하고 작업을 진행해야한다.

# openssl rsa -in keyfile.pem -out keyfile.pem

변경할 인증서의 base64 인코딩 값 확인

[root@wyj05\_deploy\_0 cert\]# cat test2.key |base64 -w 0
LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2d0lCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktrd2dnU2xBZ0VBQW9JQkFRRFBLNDJSVUZPSHVtb0UKY0FZZEo3cU9qTEtkZGxkQTVDd0ZXbWlxbWNlQlZHc01UU2kzOEdYMTBJQXl2NEhPd01Fem9DVmRvNkJFcTlaNgpLVVNuVC9VakpuQmhBazhzNEs4NlhBRi9CQ3VTSFZ3SlV2MFFiNGVWUEZwaUcvWXNsR2pUY2tsUGFFUDhYU1NDCjl6ajhiZTFZUlQ5ZEpTYmhLSUcydHF2WXdqKzFJY3VFam5qZkVvZS8wQ3F0clZRbUdWT0YzbHJiakZYYXlTUGUKYXdSUy9wZTd1NnZwWmVCbTFoRlN6eGhjdWhOaXk0Z2dzaVNZU2VXakR3cFErU1g2L1k5d0hwbFlkYkkyL25HZQpMdkJQdk01eWhBVnBkMW1Ea0xOTHpyTTF2c2RDZi9yQlkwWTdKbWVZNjJicmNjbUdFMEhSdGRuYUZhSzlybVcrCkdGa2JlZWV2QWdNQkFBRUNnZ0VCQUs5eXhRdkJxVndUSldIb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alhwU0dRQ01wNzhncGE5V2tNYy94SzgyTlZ5YUdMK3E3cDIyRnJQZnVkdWlZbGtuWlFncW9FTmp2dm1rKwpqUHpNb3RseHNmdjd3WVgrL1NMRTIwc0x1QzBrZlVUQU5sN2ZMNmEyRzYrV0hYV0VNMm5WY1FrMWRVMGpQaGlPCm8zUXM1aHU3ZEg2NAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==

위 Output을 secret edit를 하거나 manifest를 수정하여 apply하면 된다.
현 게시물에서는 edit로 수정을 진행한다.


\[root@wyj05\_deploy\_0 cert\]# kubectl edit secrets -n https test1  
(생략)  
data:  
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURaVENDQWsyZ0F3SUJBZ0lVRGJQUEtyaFpQRGg0YjVSODlnd29ka3RpazlZd0RRWUpLb1pJaHZjTkFRRUwKQlFBd1FqRUxNQWtHQTFVRUJoTUNXRmd4RlRBVEJnTlZCQWNNREVSbFptRjFiSFFnUTJsMGVURWNNQm9HQTFVRQpDZ3dUUkdWbVlYVnNkQ0J...  
tls.key: LS0tLS1CRUdJTiBQUklWQVRFIEtFWS0tLS0tCk1JSUV2d0lCQURBTkJna3Foa2lHOXcwQkFRRUZBQVNDQktrd2dnU2xBZ0VBQW9JQkFRRFBLNDJSVUZPSHVtb0UKY0FZZEo3cU9qTEtkZGxkQTVDd0ZXbWlxbWNlQlZHc01UU2kzOEdYMTBJQXl2NEhPd01Fem9DVmRvNkJFcTlaNgpLVVNuVC9VakpuQmhBazhzNEs4...  
(생략)

인증서 갱신 확인


갱신 확인


\[root@wyj05\_deploy\_0 cert\]# kubectl get secret test1 -n https -o "jsonpath={.data\['tls.crt'\]}" | base64 -d | openssl x509 -enddate -noout  
notAfter=Dec 3 03:57:39 2021 GMT

인증서 만료 날짜가 변경됐음을 알 수 있다.

Nov 30 08:32:54 2021 GMT > Dec 3 03:57:39 2021 GMT  
반응형