Unable To Create KongPlugin Resources In K8s


#1

Hi There,

I am working with k8s and am using kong 0.14 as my ingress controller. I am trying to add some plugins to various services but they never show up. I exec into the ingress controller and do curl localhost:8081/services and see there are no plugins.

Below is my kubectl deployment definition, I am adding the cors plugin to the services with an annotation:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: mygunicorn-gunicorn
spec:
   replicas: 3
   selector:
      matchLabels:
         app: mygunicorn-gunicorn
   template:
      metadata:
         labels:
            app: mygunicorn-gunicorn
      spec:
         containers:
            - name: mygunicorn-gunicorn
              image: docker.weightrack.io/mygunicorn-gunicorn
              env:
              - name: GUNICORN_WORKERS
                value: "5"

---

apiVersion: v1
kind: Service
metadata:
  name: mygunicorn-gunicorn
  labels:
     app: mygunicorn-gunicorn
  annotations:
     plugins.konghq.com: mygunicorn-kong-cors
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
    name: mygunicorn-gunicorn-http
  selector:
    app: mygunicorn-gunicorn

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: api.weightrack.io-mygunicorn-gunicorn
spec:
   rules:
     - host: api.weightrack.io
       http:
         paths:
           - path: /mygunicorn
             backend:
               serviceName: mygunicorn-gunicorn
               servicePort: 80

---

apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name: mygunicorn-kong-cors
  namespace: kong
plugin: cors
config:
    origins:
        - api.weightrack.io
        - app.weightrack.io
    methods:
        - GET
        - HEAD
        - PUT
        - PATCH
        - POST
    preflight_continue: "true"

After looking at the documents, I am not sure what config piece I am missing. I have tried making the plugin be namespaced for “kong” and “default” (where my app resides), I have also tried adding the annotation to the service and the controller to no success.

Can anyone advise? The docs on KongPlugins and how to add them to services is pretty weak at the moment so I am struggling for guidance.

I have also tried using config.<config item> in the config block with no luck.


#2

Hello @James_Young,

Creating the KongPlugin mygunicorn-kong-cors resource in the same namespace as your service mygunicorn-gunicorn should create the plugin.
Any reference to a KongPlugin resource using plugins.konghq.com should be in the same namespace.

I exec into the ingress controller and do curl localhost:8081/services and see there are no plugins.

The endpoint you’re referring to /services should services configured in Kong and not plugins. Do you see one service being created or not?

To list plugins configured in Kong, please use /plugins endpoint on Kong’s Admin API.

Also, is your Ingress rule satisfied? Let’s make sure that your Ingress is satisfied and then we can solve the KongPlugin issue.

The docs on KongPlugins and how to add them to services is pretty weak at the moment so I am struggling for guidance.

Yes, docs are a weak area for the Ingress controller currently and we’re happy to work with the community to iterate on them and improve them. PRs welcome as well!


#3

@hbagdi That was it! I can’t believe I was that close!

Thanks so much for your help (and I actually had curled /plugins, typoed and said services instead).

Now that I actually understand this a bit better, I will for sure be opening a PR soon. Thanks again for your quick help!!!