# cert-manager(https://github.com/cert-manager/cert-manager) 구성하면 자동으로 모든 네임스페이에 secret 관리/업데이트할 수 있다.
# cert-manager Issuer/ClusterIssuer 는 인증서를 발급할 수 있는 CA (Certificate Authority) 가 필요하다.
# 그런데 서버 인증서는 최종 엔드 엔티티 인증서 (End-entity certificate) 로 다른 인증서를 발급할 권한이 없다.
# CA 인증서 확인
# CA:FALSE 면 서버 인증서로 cert-manager 에서 사용할 수 없다.
openssl x509 -in 인증서.crt -text -noout | grep -A1 "Basic Constraints"
X509v3 Basic Constraints:
CA:TRUE
for ns in $(kubectl get ns --no-headers -o custom-columns=":metadata.name" | grep -vE "ysoftman-"); do
kubectl create secret tls ysoftman-test-com-tls \
--cert=인증서.crt \
--key=인증서.key \
-n "$ns" \
-o yaml | kubectl apply -f -
done
# CA 인증서라면 cert-manager 를 사용할 수 있다.
# issuer(인증서 발급 주체) 등록하고 certificates 리소스를 추가하면 secret 을 생성한다.
# issuer -> cert-manager -> certificates -> k8s secrets
# helm chart 로 설치하는 경우
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm fetch jetstack/cert-manager
tar zxvf cert-manager-v1.18.2.tgz
cd cert-manager
# 설치
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--set installCRDs=true
# crt,key 파일이 있고 이걸 전체 네임스페이스 secret 에 반영하기
# crt,key 파일로 secret 을 cert-manager 네임스페이스에 생성
kubectl create secret tls ysoftman-tls \
--cert=인증서.crt \
--key=인증서.key \
-n cert-manager
# 전체 네임스페이스 반영을 위해 ClusterIssuer 리소스 사용해야 한다.
# 다음과 같이 위에서 생성한 secret 을 참조하도록 한다.
cat << zzz | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: ysoftman-cluster-issuer
namespace: cert-manager
spec:
ca:
secretName: ysoftman-tls
zzz
# secret 이 필요한 네임스페이스에 다음과 같이 Certificate 리소스를 만들면 cert-manager 가 해당 네임스페이스에 secret 를 생성한다.
cat << zzz | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: aaa-ysoftman-com
namespace: aaa
spec:
secretName: ysoftman-com-tls
commonName: ysoftman.com
dnsNames:
- ysoftman.com
- aaa.ysoftman.com
issuerRef:
kind: ClusterIssuer
name: ysoftman-cluster-issuer
zzz
comments:
댓글 쓰기