You can directly create a KongPluginBinding to bind your plugin to a Konnect entity. For a end-to-end tutorial, see Enable a Plugin with KGO.
Assuming that you have an existing and programmed KonnectGatewayControlPlane with the name cp in the default namespace, first, create a Gateway Service and a plugin with the KongService and KongPlugin CRDs:
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 -
Then, create a 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 -
And you can create a KongPluginBinding to bind them together.
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 -
Then the plugin will be successfully attached to the Service in Konnect.
Kong Operator also supports attaching plugins to a combination of entities by KongPluginBinding.
Supported combinations include:
-
Service and Route
-
Service and Consumer
-
Service and ConsumerGroup
-
Service, Route, and Consumer
-
Service, Route, and ConsumerGroup
-
Consumer and ConsumerGroup
For example, we can configure a rate-limiting plugin to a service and a consumer like this:
Create a 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 -
Create a 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 -
Create a plugin:
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 -
Then, you can create a KongPluginBinding including both references to the KongService and the KongCosumer to attach the plugin to the Service and the 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 -
You can also attach a plugin globally to a Control Plane by setting the spec.scope field to GlobalInControlPlane in the KongPluginBinding CRD.
Create a KongPluginBinding to attach a plugin globally to a Control Plane like this:
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 -
Having the KongPluginBinding created, the plugin will be attached globally to the Control Plane in Konnect.