🍳머리말
k8s상에서 TLS/SSL secret 객체를 생성하는 방법을 설명한 글입니다.{}로 감싸진 부분은 직접 입력해야합니다. 인증서로 통신하는 보안 protocol이 TSL이며 과거 SSL이라는 명칭으로 사용되었습니다.
📕Prerequisites
📔 Openssl설치
사설 CA 인증기관이 아닌 이상 무료로 인증서를 받을 수 있는 대표 기관 중 하나입니다. 맞는 OS에 설치해 openssl 명령어로 TLS 또는 SSL file을 생성할 수 있습니다.
📕생성
📔 tls.crt, tls.key
다음 명령어로 원하는 곳에 간단히 file형태로 추가할 수 있습니다.
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=foo.bar.com"
tls.crt와 tls.key 두 개 file이 생성되었다면 성공입니다.
명령어는 다음과 같은 구성입니다.
인증서는 기본으로 base64 encoding되어 있으므로 x509 option을 사용합니다.
만료일은 days option으로 1년으로 설정했습니다.
RSA암호로 2048bit의 암호 문자열을 생성해
두 file로 write하여 export 후 생성하게 됩니다.
생성시 필요한 각 항목은 test 용이므로 subj option이용해 예시 문자열로 입력했습니다.
📔 k8s상에 secret 추가
📑 명령어로 추가
kubectl create secret tls test-tls --key="tls.key" --cert="tls.crt"
📑 yaml file 작성 후 추가
1. 다음 명령어로 base64 encode된 문자열 값을 한 줄로 만들어 각각 메모장에 복사해 놓습니다.
cat tls.crt | base64 | xargs echo | sed 's/ //g'
cat tls.key | base64 | xargs echo | sed 's/ //g'
2. secret yaml file을 작성합니다.
server쪽이므로 private cert와 key를 입력한 예시입니다.
apiVersion: v1
kind: Secret
metadata:
name: tls-cert
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUREVENDQWZXZ0F3SUJBZ0lVRE1vTzlOV2NGZkE3ckthWUpCcE4zZ0IvVDBJd0RRWUpLb1pJaHZjTkFRRUwKQlFBd0ZqRVVNQklHQTFVRUF3d0xabTl2TG1KaGNpNWpiMjB3SGhjTk1qSXdOREU1TURN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UDhmWVNiYzBpZWxWZlY3RU13NHhUUnlFR3kKdWg1Ym1iNVAzdjRBZHVaT2RlRXlhZ2MyNnFqWEFzK2s1akRvcjNjQ2dZQnh1ZG5tRmRtK1ppcjlEaTV4L0twQwphZ0d2cTFNZnE3UGxJcFNzTXZvaGVhV2toc21aNUN2U211eGpNN3lzNU9odUw4dTd5MEcxeE8vaUV3Ty9lK2pKCnF2eXAxQXdkV2hQRzBSSndMdDB4UU5mMXJDUk44QnNzRXlXQ2FPN1JIUVhsT042ZHBEWUpCTDJpYVliVXdyczEKRVY3M3ovRFhJRlNteGJET1VVV1NGdz09Ci0tLS0tRU5EIFBSSVZBVEUgS0VZLS0tLS0K
* data.tls.crt의 value는 한 줄로 되어야 합니다.
3. file apply
kubectl apply -f {만든 secret yaml file 명}
📕참조
https://shocksolution.com/2018/12/14/creating-kubernetes-secrets-using-tls-ssl-as-an-example/
'Cloud' 카테고리의 다른 글
(Terraform) - 용어 정리 (0) | 2022.04.28 |
---|---|
(Terraform) - Window에 설치 (0) | 2022.04.25 |
(Kubernetes) - redis cluster statefulset예제 (0) | 2022.04.12 |
(NGINX Ingress Controller) - TCP, UDP service 노출해 redis cluster와 연결하기 (0) | 2022.04.06 |
(Kubernetes) - resouce 생성 예시 file (0) | 2022.03.31 |