Kong Operator로 여러 네임스페이스 간 시크릿 참조하기
Kong Operator로 여러 네임스페이스 간 시크릿 참조하기 (Reference Secrets across multiple namespaces with Kong Operator)
이 튜토리얼에서는 Kong Operator 환경에서 다른 네임스페이스에 있는 시크릿(Secret)을 참조하는 방법을 알아봐요. Gateway API 리소스에는 ReferenceGrant를, Kong 전용 리소스에는 KongReferenceGrant를 시크릿이 있는 네임스페이스에 생성해서 외부 네임스페이스에서의 참조를 허가하는 방식을 설명해요. 인증서와 시크릿 생성부터 그랜트 구성, 게이트웨이·서비스·라우트 설정, 검증까지 전체 과정을 단계별로 따라 할 수 있어요
출처: 문서
본문
핵심 요약
다른 네임스페이스의 Secret을 참조하려면 어떻게 해야 하나요?
Gateway API 리소스라면 ReferenceGrant를, Kong 전용 리소스라면 KongReferenceGrant를 Secret과 같은 네임스페이스에 사용해서 소스 네임스페이스에서 오는 참조를 승인하세요.
사전 준비 사항
Konnect 배포: Kong Konnect
Konnect 계정이 없다면 온보딩 마법사를 통해 빠르게 시작할 수 있어요.
-
이 튜토리얼을 완료하려면 다음 Konnect 항목들이 필요해요:
- 개인 액세스 토큰(PAT): Konnect PAT 페이지를 열고 Generate Token을 선택해서 새 개인 액세스 토큰을 만드세요.
-
개인 액세스 토큰을 환경 변수로 설정하세요:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Kong Operator 실행
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
Helm으로 Kong Operator를 설치하세요:
Konnect 배포
helm upgrade --install kong-operator kong/kong-operator -n kong-system \ --create-namespace \ --set image.tag=2.3 \ --set env.ENABLE_CONTROLLER_KONNECT=true온프레미스 배포
helm upgrade --install kong-operator kong/kong-operator -n kong-system \ --create-namespace \ --set image.tag=2.3 \cert-manager가 어드미션 및 컨버전 웹훅 인증서를 발급하고 갱신하도록 하려면, 클러스터에 cert-manager를 설치하고 다음 단계의 설치 과정에서 다음 인자를 전달해 cert-manager 통합을 활성화하세요:
--set global.webhooks.options.certManager.enabled=true이걸 활성화하지 않으면 차트가 자동으로 자체 서명 인증서를 생성하고 주입해요. 이 인증서들의 수명 주기를 관리하려면 cert-manager를 활성화하는 걸 추천해요. Kong Operator는 컨트롤 플레인과 데이터 플레인 간 mTLS 통신용 인증서에 서명할 인증 기관이 필요해요. 이 부분은 Helm 차트가 자동으로 처리해요. 커스텀 CA 인증서를 직접 제공해야 한다면, Helm 차트의
values.yaml에 있는certificateAuthority섹션을 참고해서 자체 CA 인증서를 만들고 참조하는 방법을 알아보세요.
온프레미스 배포
이 튜토리얼에는 라이선스가 필요 없지만, KongLicense를 사용해 라이선스를 추가할 수도 있어요. 라이선스가 ./license.json에 있다고 가정해요.
echo "
apiVersion: configuration.konghq.com/v1alpha1
kind: KongLicense
metadata:
name: kong-license
rawLicenseString: '$(cat ./license.json)'
" | kubectl apply -f -
기본적으로 Kong Operator는 보안상의 이유로 같은 네임스페이스 안의 리소스에 대한 참조만 허용해요. 크로스 네임스페이스 참조를 활성화하려면 대상 네임스페이스에서 다음 리소스 중 하나를 사용해야 해요:
ReferenceGrant: Gateway API 리소스에서 다른 리소스로의 참조를 승인하는 데 쓰이는 표준 Kubernetes Gateway API 리소스예요.KongReferenceGrant: Kong 리소스에서 다른 리소스로의 참조를 승인하는 데 쓰이는 Kong 전용 리소스예요.
이 예제에서는 ReferenceGrant와 KongReferenceGrant를 둘 다 사용해서 kong 네임스페이스의 Gateway가 secret-ns 네임스페이스의 TLS Secret을 참조하도록 허용하는 방법을 보여줘요.
인증서 생성하기
다음 명령어를 실행해서 자체 서명 인증서를 만드세요:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=example.localdomain.dev"
Secret 생성하기
다음 명령어를 실행해서 secret-ns 네임스페이스와 그 네임스페이스에 TLS 인증서와 키가 담긴 Secret 리소스를 만드세요:
echo "
apiVersion: v1
kind: Namespace
metadata:
name: secret-ns
---
apiVersion: v1
kind: Secret
metadata:
name: example-tls-secret
namespace: secret-ns
labels:
konghq.com/secret: 'true'
type: kubernetes.io/tls
data:
tls.crt: "$(cat tls.crt | base64)"
tls.key: "$(cat tls.key | base64)"" | kubectl apply -f -
ReferenceGrant와 KongReferenceGrant 생성하기
다음 리소스들을 만드세요:
- 다른 네임스페이스의 표준 Gateway API 리소스가 Secret에 접근할 수 있도록 허용하는
ReferenceGrant. 이 예제에서는kong네임스페이스의Gateway리소스에 접근을 허용해요. - 다른 네임스페이스의 Kong 전용 리소스가 Secret에 접근할 수 있도록 허용하는
KongReferenceGrant. 이 예제에서는kong네임스페이스의KongCertificate리소스에 접근을 허용해요.
echo '
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
name: allow-gateway-to-secret
namespace: secret-ns
spec:
from:
- group: gateway.networking.k8s.io
kind: Gateway
namespace: kong
to:
- group: ""
kind: Secret
---
apiVersion: configuration.konghq.com/v1alpha1
kind: KongReferenceGrant
metadata:
name: allow-kong-to-secret
namespace: secret-ns
spec:
from:
- group: configuration.konghq.com
kind: KongCertificate
namespace: kong
to:
- group: core
kind: Secret' | kubectl apply -f -
Gateway 구성하기
다음 리소스들을 만드세요:
kong네임스페이스.- 최신 Kong Gateway 버전과 컨트롤러 역할을 하는 Kong Operator로 게이트웨이를 구성하는
GatewayConfiguration과GatewayClass. secret-ns네임스페이스의Secret을 참조하는Gateway.
echo '
apiVersion: v1
kind: Namespace
metadata:
name: kong
---
apiVersion: gateway-operator.konghq.com/v2beta1
kind: GatewayConfiguration
metadata:
name: gateway-configuration
namespace: kong
spec:
dataPlaneOptions:
deployment:
podTemplateSpec:
spec:
containers:
- image: kong/kong-gateway:3.16
name: proxy
---
apiVersion: gateway.networking.k8s.io/v1
kind: GatewayClass
metadata:
name: gateway-class
spec:
controllerName: konghq.com/gateway-operator
parametersRef:
group: gateway-operator.konghq.com
kind: GatewayConfiguration
name: gateway-configuration
namespace: kong
---
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: kong-gateway
namespace: kong
spec:
gatewayClassName: gateway-class
listeners:
- name: https
port: 443
protocol: HTTPS
hostname: example.localdomain.dev
tls:
mode: Terminate
certificateRefs:
- group: ""
kind: Secret
name: example-tls-secret
namespace: secret-ns' | kubectl apply -f -
Service와 Route 생성하기
-
다음 명령어를 실행해서 샘플 echo Service를 만드세요:
kubectl apply -f https://developer.konghq.com/manifests/kic/echo-service.yaml -n kong -
TLS 종단 처리가 잘 작동하는지 확인하려면 샘플
HTTPRoute를 배포하세요:echo ' apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: echo-route namespace: kong spec: parentRefs: - name: kong-gateway hostnames: - example.localdomain.dev rules: - matches: - path: type: PathPrefix value: /echo backendRefs: - name: echo kind: Service port: 1027' | kubectl apply -f -
검증하기
-
Gateway의 외부 IP를 가져오세요:
export PROXY_IP=$(kubectl get gateway kong-gateway -n kong -o jsonpath='{.status.addresses[0].value}') -
연결을 테스트하세요:
curl -ivk --resolve example.localdomain.dev:443:$PROXY_IP https://example.localdomain.dev/echoTLS 핸드셰이크와 200 응답을 받게 돼요.
관련 리소스
더 알아보기 (Learn more)
- 네임스페이스 간 참조를 Konnect 인증에 적용하는 방법을 다룬 관련 튜토리얼이에요 — Reference Konnect authentication across multiple namespaces
- Konnect 계정이 없을 때 온보딩 마법사로 빠르게 시작하는 방법을 안내해요 — onboarding wizard
- 이 튜토리얼에 필요한 Konnect 개인 액세스 토큰(PAT)을 발급할 수 있는 페이지예요 — Konnect PAT page