폴백 구성으로 손상된 객체 제외하기
폴백 구성으로 손상된 객체 제외하기 (Fallback Configuration)
Kong Ingress Controller 구성에 오류가 있는 객체가 섞여 있으면 정상적인 설정까지 함께 거부될 수 있어요. 이 문서에서는 FallbackConfiguration 기능 게이트를 활성화해 손상된 객체만 제외하고 나머지 정상 구성이 계속 동작하도록 만드는 방법을 알아봐요. Konnect 또는 온프레미스 환경에서 Gateway API와 Ingress 라우트를 구성한 뒤, 의도적으로 라우트를 깨뜨려 폴백 구성이 문제를 어떻게 처리하는지 단계별로 확인해 봐요
출처: 문서
본문
TL;DR
Kong Ingress Controller 설정에서 깨진 일부는 어떻게 제외하나요?
Kong Ingress Controller에서 FallbackConfiguration feature gate를 활성화하세요
필수 조건
Konnect 배포: Kong Konnect
Konnect 계정이 없다면, 온보딩 마법사를 통해 빠르게 시작할 수 있어요.
-
이 튜토리얼을 완료하려면 다음 Konnect 항목들이 필요해요:
- 개인 액세스 토큰(PAT): Konnect PAT 페이지를 열고 Generate Token을 선택해서 새 개인 액세스 토큰을 만드세요.
-
개인 액세스 토큰을 환경 변수로 설정하세요:
export KONNECT_TOKEN='YOUR KONNECT TOKEN'
Gateway API 활성화
-
Kong Ingress Controller를 설치하기 전에 Gateway API CRD를 설치하세요.
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.6.1/standard-install.yaml{: data-test-prereq="block" }
-
사용할
Gateway와GatewayClass인스턴스를 만드세요.echo " apiVersion: v1 kind: Namespace metadata: name: kong --- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: kong annotations: konghq.com/gatewayclass-unmanaged: 'true' spec: controllerName: konghq.com/kic-gateway-controller --- apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: kong spec: gatewayClassName: kong listeners: - name: proxy port: 80 protocol: HTTP allowedRoutes: namespaces: from: All " | kubectl apply -n kong -f -{: data-test-prereq="block" }
Konnect 배포: KIC 컨트롤 플레인 만들기
Konnect API를 사용해서 새로운 CLUSTER_TYPE_K8S_INGRESS_CONTROLLER 컨트롤 플레인을 만드세요:
CONTROL_PLANE_DETAILS=$(curl -X POST "https://us.api.konghq.com/v2/control-planes" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"name": "My KIC CP",
"cluster_type": "CLUSTER_TYPE_K8S_INGRESS_CONTROLLER"
}'
)
나중에 values.yaml 파일을 작성할 때 id와 telemetry_endpoint가 필요해요. 환경 변수로 저장해 두세요:
CONTROL_PLANE_ID=$(echo $CONTROL_PLANE_DETAILS | jq -r .id)
CONTROL_PLANE_TELEMETRY=$(echo $CONTROL_PLANE_DETAILS | jq -r '.config.telemetry_endpoint | sub("https://";"")')
mTLS 인증서 만들기
Kong Ingress Controller는 TLS 인증서로 보안이 유지되는 연결을 통해 Konnect와 통신해요.
openssl을 사용해서 새 인증서를 생성하세요:
openssl req -new -x509 -nodes -newkey rsa:2048 -subj "/CN=kongdp/C=US" -keyout ./tls.key -out ./tls.crt
인증서를 curl로 Konnect API에 보내려면 한 줄짜리 문자열이어야 해요. awk를 사용해서 인증서 형식을 변환하세요:
export CERT=$(awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' tls.crt);
다음으로, 인증서를 Konnect에 업로드하세요:
curl -X POST "https://us.api.konghq.com/v2/control-planes/$CONTROL_PLANE_ID/dp-client-certificates" \
--no-progress-meter --fail-with-body \
-H "Authorization: Bearer $KONNECT_TOKEN" \
--json '{
"cert": "'$CERT'"
}'
마지막으로, Kong Ingress Controller가 읽을 수 있도록 인증서를 Kubernetes 시크릿에 저장하세요:
kubectl create namespace kong -o yaml --dry-run=client | kubectl apply -f -
kubectl create secret tls konnect-client-tls -n kong --cert=./tls.crt --key=./tls.key
Konnect 배포: Kong Ingress Controller 실행 (Konnect에 연결됨)
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
values.yaml파일을 만드세요:cat <<EOF > values.yaml controller: ingressController: image: tag: "3.5" env: feature_gates: "FillIDs=true" konnect: license: enabled: true enabled: true controlPlaneID: "$CONTROL_PLANE_ID" tlsClientCertSecretName: konnect-client-tls apiHostname: "us.kic.api.konghq.com" gateway: image: repository: kong tag: "3.9.3" env: konnect_mode: 'on' vitals: "off" cluster_mtls: pki cluster_telemetry_endpoint: "$CONTROL_PLANE_TELEMETRY:443" cluster_telemetry_server_name: "$CONTROL_PLANE_TELEMETRY" cluster_cert: /etc/secrets/konnect-client-tls/tls.crt cluster_cert_key: /etc/secrets/konnect-client-tls/tls.key lua_ssl_trusted_certificate: system proxy_access_log: "off" dns_stale_ttl: "3600" secretVolumes: - konnect-client-tls EOF{: data-test-prereq="block" }
-
Helm을 사용해서 Kong Ingress Controller를 설치하세요:
helm install kong kong/ingress -n kong --create-namespace --set controller.ingressController.env.feature_gates="FallbackConfiguration=true" --set controller.ingressController.env.dump_config=true --values ./values.yaml --wait{: data-test-prereq="block" }
-
이후 명령어에서 사용할 수 있도록
$PROXY_IP를 환경 변수로 설정하세요:export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}') echo $PROXY_IP
온프레미스 배포: Kong Ingress Controller 실행
-
Kong Helm 차트를 추가하세요:
helm repo add kong https://charts.konghq.com helm repo update -
Helm을 사용해서 Kong Ingress Controller를 설치하세요:
helm install kong kong/ingress -n kong --create-namespace --set controller.ingressController.env.feature_gates="FallbackConfiguration=true" --set controller.ingressController.env.dump_config=true --wait{: data-test-prereq="block" }
-
이후 명령어에서 사용할 수 있도록
$PROXY_IP를 환경 변수로 설정하세요:export PROXY_IP=$(kubectl get svc --namespace kong kong-gateway-proxy -o jsonpath='{range .status.loadBalancer.ingress[0]}{@.ip}{@.hostname}{end}') echo $PROXY_IP
필요한 Kubernetes 리소스
이 가이드에서는 클러스터에서 몇 가지 Kubernetes 서비스를 사용할 수 있어야 해요. 이 가이드에서 만드는 리소스들이 이 서비스들을 사용하게 돼요.
kubectl apply -f https://developer.konghq.com/manifests/kic/echo-service.yaml -n kong
{: data-test-prereq="block" }
서비스의 pod들이 준비될 때까지 기다리세요:
kubectl wait --for=condition=Ready pod --all -n kong --timeout=300s
{: data-test-prereq="block" }
시나리오
이 예제에서는 다음과 같은 상황을 생각해 볼 거예요:
- 같은
Service를 가리키는 두 개의 Route가 있어요. 그중 하나의 Route에는 인증과 기본 rate limiting을 제공하는KongPlugin들이 구성되어 있고, 모든 게 예상대로 동작하고 있어요. - 기본 rate limiting과 다른 방식으로 rate limit이 적용되도록, 두 번째 Route와 특정
KongConsumer에 연결될 rate limitingKongPlugin을 하나 더 추가해요. 하지만KongConsumer를KongPlugin과 연결하는 것을 잊어버려요. 그 결과 중복된 rate limiting 플러그인 때문에 Route가 깨지게 돼요.
플러그인 구성
이 가이드에서는 fallback configuration이 어떻게 동작하는지 보여주기 위해 세 개의 플러그인이 필요해요.
-
예제에서 Consumer를 사용하기 때문에, 들어오는 요청을 식별할 인증 플러그인을 만들어야 해요:
echo " apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: key-auth namespace: kong annotations: kubernetes.io/ingress.class: kong plugin: key-auth " | kubectl apply -f - -
식별되지 않은 트래픽에는 초당 1회 요청이라는 기본 rate limit이 적용돼요:
echo " apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: rate-limit-base namespace: kong annotations: kubernetes.io/ingress.class: kong plugin: rate-limiting config: second: 1 policy: local " | kubectl apply -f - -
식별된 Consumer에는 초당 5회 요청이라는 rate limit이 적용돼요:
echo " apiVersion: configuration.konghq.com/v1 kind: KongPlugin metadata: name: rate-limit-consumer namespace: kong annotations: kubernetes.io/ingress.class: kong plugin: rate-limiting config: second: 5 policy: local " | kubectl apply -f -
Route 만들기
테스트를 위해 두 개의 Route를 만들어 볼게요:
route-a에는 연결된 플러그인이 없어요route-b에는 위에서 만든 세 개의 플러그인이 연결되어 있어요
Gateway API
echo "
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: route-a
namespace: kong
annotations:
konghq.com/strip-path: 'true'
spec:
parentRefs:
- name: kong
namespace: kong
rules:
- matches:
- path:
type: PathPrefix
value: '/route-a'
backendRefs:
- name: echo
kind: Service
port: 1027
" | kubectl apply -f -
{: data-test-step="block" }
Ingress
echo "
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: route-a
namespace: kong
annotations:
konghq.com/strip-path: 'true'
spec:
ingressClassName: kong
rules:
- http:
paths:
- path: '/route-a'
pathType: ImplementationSpecific
backend:
service:
name: echo
port:
number: 1027
" | kubectl apply -f -
Gateway API
echo "
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: route-b
namespace: kong
annotations:
konghq.com/plugins: key-auth,rate-limit-base,rate-limit-consumer
konghq.com/strip-path: 'true'
spec:
parentRefs:
- name: kong
namespace: kong
rules:
- matches:
- path:
type: PathPrefix
value: '/route-b'
backendRefs:
- name: echo
kind: Service
port: 1027
" | kubectl apply -f -
{: data-test-step="block" }
Ingress
echo "
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: route-b
namespace: kong
annotations:
konghq.com/strip-path: 'true'
spec:
ingressClassName: kong
rules:
- http:
paths:
- path: '/route-b'
pathType: ImplementationSpecific
backend:
service:
name: echo
port:
number: 1027
" | kubectl apply -f -
Consumer 만들기
마지막으로, 자격 증명이 있는 KongConsumer를 만들고 rate-limit-consumer KongPlugin을 연결해 볼게요.
key-auth 자격 증명이 담긴 Secret을 만드세요:
echo 'apiVersion: v1
kind: Secret
metadata:
name: bob-key-auth
namespace: kong
labels:
konghq.com/credential: key-auth
stringData:
key: bob-password
' | kubectl apply -f -
그다음, 이 Secret을 참조하는 KongConsumer를 만드세요:
echo "
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: bob
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: rate-limit-consumer
username: bob
credentials:
- bob-key-auth
" | kubectl apply -f -
Route 검증
이 시점에서 Route들이 예상대로 동작하는지 확인할 수 있어요.
Route A
route-a는 인증 없이 접근할 수 있고 HTTP 200을 반환해요:
Konnect 배포
curl "$PROXY_IP/route-a" \
--no-progress-meter --fail-with-body
온프레미스 배포
curl "$PROXY_IP/route-a" \
--no-progress-meter --fail-with-body
결과는 다음과 같아야 해요:
Welcome, you are connected to node orbstack.
Running on Pod echo-74c66b778-szf8f.
In namespace default.
With IP address 192.168.194.13.
{:.no-copy-code}
Route B
route-b에서 유효한 apikey 헤더와 함께 보낸 인증된 요청은 수락되어야 해요:
Konnect 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body \
-H "apikey:bob-password"
온프레미스 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body \
-H "apikey:bob-password"
결과는 다음과 같아야 해요:
Welcome, you are connected to node orbstack.
Running on Pod echo-74c66b778-szf8f.
In namespace default.
With IP address 192.168.194.13.
{:.no-copy-code}
apikey 헤더가 없는 요청은 거부되어야 해요:
Konnect 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body
온프레미스 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body
결과는 다음과 같이 표시돼요:
{
"message":"No API key found in request",
"request_id":"520c396c6c32b0400f7c33531b7f9b2c"
}
{:.no-copy-code}
호환성이 깨지는 변경 만들기
이제 설정에 호환성이 깨지는 변경을 가하는 상황을 시뮬레이션해 봐요. KongConsumer에서 rate-limit-consumer KongPlugin을 제거하면 route-b에 이제 두 개의 rate-limiting 플러그인이 연결되는데, 이는 유효하지 않은 Kong Gateway 설정이에요:
kubectl annotate -n kong kongconsumer bob konghq.com/plugins-
깨진 라우트가 제외됐는지 확인하기
같은 타입(rate-limiting)을 사용하는 KongPlugin이 두 개 있기 때문에 route-b는 깨지게 돼요. route-b가 설정에서 제외될 거예요.
이를 확인해 봐요:
Konnect 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body
온프레미스 배포
curl "$PROXY_IP/route-b" \
--no-progress-meter --fail-with-body
결과는 다음과 같이 표시돼요:
{
"message":"no Route matched with those values",
"request_id":"209a6b14781179103528093188ed4008"
}%
{:.no-copy-code}
진단 엔드포인트 살펴보기
Fallback Configuration 메커니즘이 깨진 HTTPRoute를 제외하고 있기 때문에 Route가 설정되지 않아요.
진단 엔드포인트를 살펴봐서 이를 확인할 수 있어요:
kubectl port-forward -n kong deploy/kong-controller 10256 &
sleep 0.5; curl localhost:10256/debug/config/fallback | jq
결과는 다음과 같이 표시돼요:
{
"status": "triggered",
"brokenObjects": [
{
"group": "configuration.konghq.com",
"kind": "KongPlugin",
"namespace": "default",
"name": "rate-limit-consumer",
"id": "7167315d-58f5-4aea-8aa5-a9d989f33a49"
}
],
"excludedObjects": [
{
"group": "configuration.konghq.com",
"kind": "KongPlugin",
"version": "v1",
"namespace": "default",
"name": "rate-limit-consumer",
"id": "7167315d-58f5-4aea-8aa5-a9d989f33a49",
"causingObjects": [
"configuration.konghq.com/KongPlugin:default/rate-limit-consumer"
]
},
{
"group": "gateway.networking.k8s.io",
"kind": "HTTPRoute",
"version": "v1",
"namespace": "default",
"name": "route-b",
"id": "fc82aa3d-512c-42f2-b7c3-e6f0069fcc94",
"causingObjects": [
"configuration.konghq.com/KongPlugin:default/rate-limit-consumer"
]
}
]
}
{:.no-copy-code}
정상 동작하는 Route가 여전히 작동하고 업데이트 가능한지 확인하기
다른 HTTPRoute가 여전히 작동하는지도 확인할 수 있어요:
Konnect 배포
curl "$PROXY_IP/route-a" \
--no-progress-meter --fail-with-body
온프레미스 배포
curl "$PROXY_IP/route-a" \
--no-progress-meter --fail-with-body
결과는 다음과 같이 표시돼요:
Welcome, you are connected to node orbstack.
Running on Pod echo-74c66b778-szf8f.
In namespace default.
With IP address 192.168.194.13.
게다가 정상적인 HTTPRoute는 여전히 문제 없이 업데이트할 수 있어요. route-a의 경로를 수정해 봐요:
kubectl patch -n kong httproute route-a --type merge -p '{"spec":{"rules":[{"matches":[{"path":{"type":"PathPrefix","value":"/route-a-modified"}}],"backendRefs":[{"name":"echo","port":1027}]}]}}'
업데이트된 HTTPRoute를 확인해 봐요:
Konnect 배포
curl "$PROXY_IP/route-a-modified" \
--no-progress-meter --fail-with-body
온프레미스 배포
curl "$PROXY_IP/route-a-modified" \
--no-progress-meter --fail-with-body
결과는 다음과 같이 표시돼요:
Welcome, you are connected to node orbstack.
Running on Pod echo-74c66b778-szf8f.
In namespace default.
With IP address 192.168.194.13.
{:.no-copy-code}
Fallback Configuration 메커니즘이 깨진 HTTPRoute를 성공적으로 격리하고 정상적인 HTTPRoute는 업데이트할 수 있게 해줬어요.
정리
생성한 Kubernetes 리소스 삭제하기
kubectl delete -n kong -f https://developer.konghq.com/manifests/kic/echo-service.yaml
클러스터에서 KIC 제거하기
helm uninstall kong -n kong
관련 리소스
더 알아보기 (Learn more)
- 폴백 구성의 개념과 동작 방식을 먼저 훑어보고 싶다면 — Fallback configuration overview
- 깨진 구성을 복구해 다시 반영하는 절차가 궁금하다면 — How-To: Backfill broken configuration
- 이 실습에서 만드는 Consumer 엔티티의 자세한 스펙이 필요하다면 — Consumer
- Konnect 계정이 아직 없다면 온보딩 마법사로 빠르게 시작할 수 있어요 — onboarding wizard