본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

KongPluginBinding 이해하기

원문 보기 위키 갱신

KongPluginBinding 이해하기 (Understanding KongPluginBinding)

KongPluginBinding은 플러그인과 Konnect 엔티티(서비스, 라우트, 컨슈머, 컨슈머 그룹)를 연결하는 CRD예요. 이 문서에서는 주요 필드와 사용 방법을 설명하고, unmanaged 방식으로 직접 바인딩하는 예제를 제공해요. 또한 여러 엔티티에 플러그인을 연결하거나 전역으로 바인딩하는 방법도 다루고 있어요.

출처: 문서

본문

KongPluginBinding은 플러그인과 연결된 Konnect 엔티티(서비스, 라우트, 컨슈머, 컨슈머 그룹 또는 이들 엔티티의 지원되는 조합) 간의 바인딩 관계를 관리하는 CRD예요.

v1.5+에서는 spec.scope를 GlobalInControlPlane으로 설정하면 플러그인을 컨트롤 플레인에 전역으로 바인딩하는 데에도 사용할 수 있어요.

각 KongPluginBinding은 Konnect에서 하나의 플러그인 인스턴스를 나타내요.

이 CRD에는 다음과 같은 필드가 있어요:

  • spec.pluginRef: 플러그인의 이름과 구성을 포함하는 KongPlugin 객체를 참조해요.
  • spec.targets: 플러그인이 연결되는 엔티티 또는 엔티티 조합을 참조해요. spec.scope가 OnlyTargets(기본값)일 때는 하나 이상의 대상을 지정해야 해요.
  • spec.controlPlaneRef: 이 KongPluginBinding이 연결된 Kong Konnect 컨트롤 플레인을 참조해요.

사용 가능한 모든 필드를 보려면 사용자 정의 리소스 API를 참조하세요.

참고: KongPluginBinding은 Konnect의 Plugin API를 1:1로 모델링하므로 Service, Route, Consumer, Consumer Group과 같은 Kong 엔티티만 지원해요. HTTPRoute에 플러그인을 연결하려면 이 가이드에서 지원되는 방법을 확인하세요.

관리되지 않는 KongPluginBinding 사용하기

KongPluginBinding을 직접 생성하여 플러그인을 Konnect 엔티티에 바인딩할 수 있어요. 전체 튜토리얼은 KO로 플러그인 활성화하기를 참조하세요.

default 네임스페이스에 cp라는 이름의 KonnectGatewayControlPlane이 이미 존재하고 프로그래밍되어 있다고 가정할게요. 먼저 KongService와 KongPlugin CRD를 사용하여 Gateway Service와 플러그인을 생성하세요:

echo '
kind: KongService
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: service-example
spec:
  host: example.com
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

그런 다음 KongPlugin을 생성하세요:

echo '
kind: KongPlugin
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: rate-limiting-minute-10
plugin: rate-limiting
config:
  policy: local
  minute: 10
' | kubectl apply -f -

그리고 KongPluginBinding을 생성하여 함께 바인딩할 수 있어요.

echo '
kind: KongPluginBinding
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: binding-service-example-rate-limiting
spec:
  pluginRef:
    kind: KongPlugin
    name: rate-limiting-minute-10
  targets:
    serviceRef:
      group: configuration.konghq.com
      kind: KongService
      name: service-example
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

그러면 플러그인이 Konnect의 Service에 성공적으로 연결될 거예요.

여러 엔티티에 플러그인 연결하기

Kong Operator는 KongPluginBinding을 통해 엔티티 조합에 플러그인을 연결하는 것도 지원해요. 지원되는 조합은 다음과 같아요:

  • Service and Route
  • Service and Consumer
  • Service and ConsumerGroup
  • Service, Route, and Consumer
  • Service, Route, and ConsumerGroup
  • Consumer and ConsumerGroup

예를 들어, rate-limiting 플러그인을 서비스와 컨슈머에 다음과 같이 구성할 수 있어요:

Service 생성:

echo '
kind: KongService
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: service-plugin-binding-combination
spec:
  host: example.com
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

Consumer 생성:

echo '
kind: KongConsumer
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: consumer-plugin-binding-combination
username: consumer-test
spec:
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

플러그인 생성:

echo '
kind: KongPlugin
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: rate-limiting-minute-10
plugin: rate-limiting
config:
  policy: local
  minute: 10
' | kubectl apply -f -

그런 다음 KongService와 KongCosumer에 대한 참조를 모두 포함하는 KongPluginBinding을 생성하여 플러그인을 Service와 Consumer에 연결할 수 있어요:

echo '
kind: KongPluginBinding
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: binding-combination-service-consumer
spec:
  pluginRef:
    kind: KongPlugin
    name: rate-limiting-minute-10
  targets:
    serviceRef:
      group: configuration.konghq.com
      kind: KongService
      name: service-plugin-binding-combination
    consumerRef:
      name: consumer-plugin-binding-combination
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

컨트롤 플레인에 플러그인을 전역으로 연결하기 v1.5+

KongPluginBinding CRD에서 spec.scope 필드를 GlobalInControlPlane으로 설정하여 플러그인을 컨트롤 플레인에 전역으로 연결할 수도 있어요.

다음과 같이 KongPluginBinding을 생성하여 플러그인을 컨트롤 플레인에 전역으로 연결하세요:

echo '
kind: KongPluginBinding
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: binding-global-rate-limiting
spec:
  # This indicates that the plugin is attached globally to the control plane and allows leaving targets empty.
  scope: GlobalInControlPlane
  pluginRef:
    kind: KongPlugin
    name: rate-limiting-minute-10
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

KongPluginBinding이 생성되면 플러그인이 Konnect의 컨트롤 플레인에 전역으로 연결될 거예요.

어노테이션을 사용하여 플러그인을 다른 엔티티에 바인딩하기

참고: 이 방법은 레거시로 간주되며, 대신 KongPluginBinding CRD를 사용하는 것이 권장돼요. konghq.com/plugins 어노테이션 지원은 향후 언젠가 제거될 예정이에요.

konghq.com/plugins 어노테이션을 사용하여 Kong Ingress Controller에서 하는 것처럼 플러그인을 다른 엔티티에 연결할 수도 있어요. Kong Operator는 어노테이션에 대한 KongPluginBinding 리소스를 생성하고 Konnect에서 구성할 거예요.

위 예제에서는 다음과 같이 KongPlugin과 KongService를 생성할 수 있어요:

echo '
kind: KongPlugin
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: rate-limiting-minute-10
plugin: rate-limiting
config:
  policy: local
  minute: 10
' | kubectl apply -f - 
echo '
kind: KongService
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: service-example
  annotations:
    konghq.com/plugins: rate-limiting-minute-10
spec:
  host: example.com
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

이 시점에서 플러그인이 Konnect의 Service에 연결된 것을 확인할 수 있어요.

다음 명령을 실행하여 KongPluginBinding 리소스를 확인할 수도 있어요.

kubectl get kongpluginbinding

생성된 KongPluginBinding은 다음과 같이 확인할 수 있어요:

NAME                            PLUGIN-KIND   PLUGIN-NAME                  PROGRAMMED
rate-limiting-minute-10-a0z1x   KongPlugin    rate-limiting-minute-10      True

여러 엔티티에 플러그인 연결하기

참고: 이 방법으로 플러그인을 바인딩하면 관찰 가능성이 제한적이고, 여러 다른 리소스가 동일한 플러그인에 연결될 때 예기치 않은 결과가 발생할 수 있어요. (예: Service에 이미 플러그인이 연결되어 있고 동일한 플러그인으로 Consumer에 어노테이션을 추가하는 경우) 더 나은 제어와 감사 가능성을 위해 KongPluginBinding CRD를 사용하는 것이 좋아요.

위에서 소개한 것과 유사하게, 연결된 엔티티의 어노테이션을 구성하여 플러그인을 여러 엔티티에 연결할 수도 있어요. 플러그인이 여러 엔티티의 konghq.com/plugins 어노테이션에 나타나면, 플러그인과 이들 엔티티 조합 간의 바인딩 관계에 대한 KongPluginBinding이 생성돼요. 위의 예시처럼 플러그인이 Service와 Consumer에 연결된 경우를 들어볼게요:

echo '
kind: KongPlugin
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: rate-limiting-minute-10
plugin: rate-limiting
config:
  policy: local
  minute: 10
' | kubectl apply -f -
echo '
kind: KongService
apiVersion: configuration.konghq.com/v1alpha1
metadata:
  namespace: default
  name: service-plugin-binding-combination
  annotations:
    konghq.com/plugins: rate-limiting-minute-10
spec:
  host: example.com
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -
echo '
kind: KongConsumer
apiVersion: configuration.konghq.com/v1
metadata:
  namespace: default
  name: consumer-plugin-binding-combination
  annotations:
    konghq.com/plugins: rate-limiting-minute-10
username: consumer-test
spec:
  controlPlaneRef:
    type: konnectNamespacedRef
    konnectNamespacedRef:
      name: cp
' | kubectl apply -f -

spec.targets에 serviceRef와 consumerRef가 모두 포함된 KongPluginBinding이 다음과 같이 생성돼요:

apiVersion: configuration.konghq.com/v1alpha1
kind: KongPluginBinding
metadata:
  creationTimestamp: "2024-10-14T07:14:05Z"
  generateName: rate-limiting-minute-10-
  name: rate-limiting-minute-10-xyz98
  namespace: default
  ownerReferences:
  - apiVersion: configuration.konghq.com/v1
    blockOwnerDeletion: true
    kind: KongPlugin
    name: rate-limiting-minute-10
    uid: 01234567-89ab-cdef-fdec-ba9876543210
spec:
  controlPlaneRef:
    konnectNamespacedRef:
      name: test1
      namespace: default
    type: konnectNamespacedRef
  pluginRef:
    kind: KongPlugin
    name: rate-limiting-minute-10
  targets:
    consumerRef:
      name: consumer-plugin-binding-combination
    serviceRef:
      group: configuration.konghq.com
      kind: KongService
      name: service-plugin-binding-combination

관련 리소스

더 알아보기 (Learn more)

  • KongPluginBinding의 전체 필드와 API 레퍼런스를 확인할 수 있어요. — API
  • HTTPRoute에 플러그인을 연결하는 다른 방법을 알아보세요. — this guide
  • KongPluginBinding을 사용한 엔드투엔드 튜토리얼을 확인해보세요. — Enable a plugin with KO