본문 바로가기

Web/웹 상식

[Kubernetes] Kubernetes tls Secret 생성하기

Kubernetes에 TLS secret을 추가해야 할 일이 있어서 정리해놓으면 편하겠다 싶어서 정리하게 됐습니다.

 

  1. Openssl을 이용해서 Private Key, Public Key 생성
  2. Private Key를 이용한 CSR(Certificate Signing Request 생성)
  3. CRT 인증서 만들기
  4. CRT파일을 PEM파일로 변환
  5. Kubernetes에 secret 생성

1. Openssl을 이용해서 Private Key, Public Key 생성

  • Private Key 생성 명령어
    • openssl genrsa -out [파일명] [bit길이]
      
      예시) openssl genrsa -out test.key 2048
  • Public Key 생성 명령어
    • openssl rsa -in [privateKey 파일명] -pubout -out [파일명]
      
      예시) openssl rsa -in test.key -pubout -out test_pub.key

2. Private Key를 이용한 CSR(Certificate Signing Request 생성)

  • CSR생성 명령어
    • openssl req -new -key [privateKey 파일명] -out [파일명]
      
      예시) openssl req -new -key test.key -out test.csr
  • 생성 옵션 입력
    • // 이 부분은 임시로 작성한 내용입니다.
      // 외부로 서비스 할 때는 공인 사이트에서 인증서를 발급 받아서 사용해야합니다.
      // 직접 작성해서 사용하는 것은 사설 서버에서 사용합니다.
      Country Name (2 letter code) [AU]: KR
      State or Province Name (full name) [Some-State]: Seoul
      Locality Name (eg, city) []: Seoul
      Organization Name (eg, company) [Internet Widgits Pty Ltd]: example
      Organization Unit Name (eg, section) []: example
      Common Name (eg, YOUR name) []: test
      Email Address []: test@test.com
      
      Please enter the following 'extra' attributes
      to be sent with your certificate request
      A challenge password []: test

3. CRT 인증서 만들기

  • CRT 인증서 생성 명령어
    • openssl req -x509 -days [유효기간] -key [privateKey 파일명] -in [csr파일명] -out [파일명] -days [유효기간]
      
      예시) openssl req -x509 -days 365 -key test.key -in test.csr -out test.crt -days 365

4. CRT파일을 PEM파일로 변환

  • PEM 변환 명령어
    • openssl x509 -in [crt파일명] -out [파일명] -outform PEM
      
      예시) openssl x509 -in test.crt -out test.pem -outform PEM

5. Kubernetes에 secret 생성

  • secret 생성 명령어
    • //이미 동일한 이름의 secret이 존재한다면 아래의 명령어로 삭제합니다.
      // kubectl delete secret [secret명] -n [namespace명]
      
      kubectl create secret tls [secret명] --key [privateKey 파일명] --cert [crt 파일명] -n [kubernetes namespace명]
      
      예시) kubectl create secret tls test-secret --key test.key --cert test.crt -n dev

 

반응형

'Web > 웹 상식' 카테고리의 다른 글

배포 전략에 대해서  (0) 2022.05.25
[Spring] @InitBinder에 대해서  (0) 2022.03.31
[Spring Cloud] Feign에 대해서  (0) 2021.10.09
URI와 URL의 차이  (0) 2021.08.19
[GraphQL] GraphQL 처음 시작하기  (0) 2021.08.12