Kong Ingress Controller doesn't start when PHP FPM server is included

Hi.

I am trying to set up a server block for fpm container as described here: https://itnext.io/containerizing-symfony-application-a2a5a3bd5edc

I have set up the fpm container and it is serving correctly. However, when I put the Nginx fpm server block and pass it on to Kong using HTTP include env, the DB less ingress controller, with proxy, doesn’t start.

What is going wrong here?
Thanks!

Do you see anything in the logs of Kong?

I’m not sure you can use directive injection to add an entire server block–normally those are handled by editing the template, adding a new server block after the include at https://github.com/Kong/kong/blob/master/kong/templates/nginx.lua#L18-L20. That modified template then needs to be copied into a custom Docker image at /usr/local/share/lua/5.1/kong/template/nginx.lua (or mounted there from a ConfigMap).

Along with the logs, can you show exactly how you have this currently configured in kong.conf/environment variables?

I am using Kong 2.0.2-alpine

Here is the describe output:

Name:           kong-dbless-54776b644d-mf75c
Namespace:      abc
Priority:       0
Node:           docker-desktop/192.168.65.3
Start Time:     Sat, 11 Apr 2020 13:55:14 +0200
Labels:         app=kong-dbless
                pod-template-hash=54776b644d
Annotations:    <none>
Status:         Running
IP:             10.1.0.137
IPs:            <none>
Controlled By:  ReplicaSet/kong-dbless-54776b644d
Containers:
  kong-proxy:
    Container ID:   docker://f8e0cba69bdfad0b2f96b1f398b6902d8d1be8b1583748de88b10be17387b54c
    Image:          registry.example.com/kong:latest
    Image ID:       docker-pullable://registry.example.com/kong@sha256:b58fee218f436723c6c4c7cf2b0326dd448e5c62e168f0869734220720ca726c
    Ports:          8000/TCP, 8443/TCP, 8001/TCP
    Host Ports:     0/TCP, 0/TCP, 0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Sat, 11 Apr 2020 13:55:16 +0200
      Finished:     Sat, 11 Apr 2020 13:55:16 +0200
    Ready:          False
    Restart Count:  1
    Liveness:       tcp-socket :8000 delay=15s timeout=1s period=20s #success=1 #failure=3
    Readiness:      tcp-socket :8000 delay=5s timeout=1s period=10s #success=1 #failure=3
    Environment:
      KONG_DATABASE:                off
      KONG_NGINX_WORKER_PROCESSES:  1
      KONG_NGINX_HTTP_INCLUDE:      /kong/servers.conf
      KONG_ADMIN_ACCESS_LOG:        /dev/stdout
      KONG_ADMIN_ERROR_LOG:         /dev/stderr
      KONG_ADMIN_LISTEN:            0.0.0.0:8001, 0.0.0.0:8444 ssl
      KONG_PROXY_LISTEN:            0.0.0.0:8000, 0.0.0.0:8443 ssl http2
      KONG_HEADERS:                 off
    Mounts:
      /kong from kong-server-blocks (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-j9669 (ro)
  ingress-controller:
    Container ID:  docker://ac00d030e90a72d983c488cdf675917a125aa87746ca2c99fe46cdf31b059c15
    Image:         kong-docker-kubernetes-ingress-controller.bintray.io/kong-ingress-controller:0.8.0
    Image ID:      docker-pullable://kong-docker-kubernetes-ingress-controller.bintray.io/kong-ingress-controller@sha256:4bc984a937cefa1aba1cfe283d757e959350abd3143178b44e415dd0d40680ab
    Port:          8080/TCP
    Host Port:     0/TCP
    Args:
      /kong-ingress-controller
      --kong-admin-url=https://localhost:8444
      --admin-tls-skip-verify
      --publish-service=abc/svc-kong-dbless
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Sat, 11 Apr 2020 13:55:16 +0200
      Finished:     Sat, 11 Apr 2020 13:55:16 +0200
    Ready:          False
    Restart Count:  1
    Liveness:       http-get http://:10254/healthz delay=60s timeout=1s period=10s #success=1 #failure=10
    Readiness:      http-get http://:10254/healthz delay=0s timeout=1s period=10s #success=1 #failure=10
    Environment:
      POD_NAME:       kong-dbless-54776b644d-mf75c (v1:metadata.name)
      POD_NAMESPACE:  abc (v1:metadata.namespace)
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-j9669 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  kong-server-blocks:
    Type:      ConfigMap (a volume populated by a ConfigMap)
    Name:      kong-server-blocks
    Optional:  false
  default-token-j9669:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-j9669
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type     Reason     Age                From                     Message
  ----     ------     ----               ----                     -------
  Normal   Scheduled  13s                default-scheduler        Successfully assigned abc/kong-dbless-54776b644d-mf75c to docker-desktop
  Normal   Pulled     11s (x2 over 12s)  kubelet, docker-desktop  Container image "registry.example.com/kong:latest" already present on machine
  Normal   Created    11s (x2 over 12s)  kubelet, docker-desktop  Created container kong-proxy
  Normal   Started    11s (x2 over 12s)  kubelet, docker-desktop  Started container kong-proxy
  Normal   Pulled     11s (x2 over 12s)  kubelet, docker-desktop  Container image "kong-docker-kubernetes-ingress-controller.bintray.io/kong-ingress-controller:0.8.0" already present on machine
  Normal   Created    11s (x2 over 12s)  kubelet, docker-desktop  Created container ingress-controller
  Normal   Started    11s (x2 over 12s)  kubelet, docker-desktop  Started container ingress-controller
  Warning  BackOff    4s (x4 over 10s)   kubelet, docker-desktop  Back-off restarting failed container
  Warning  BackOff    4s (x4 over 10s)   kubelet, docker-desktop  Back-off restarting failed container

Here is the ConfigMap:

---
apiVersion: v1
data:
  servers.conf: |
    server {
        server_name _;
        listen 80;
        root /app/public;

        location / {
            try_files $uri /index.php$is_args$args;
        }

        location ~ ^/index\.php(/|$) {
            fastcgi_pass svc-fpm:9000;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param DOCUMENT_ROOT $document_root;
            internal;
        }

        location ~ \.php$ {
            return 404;
        }
    }
kind: ConfigMap
metadata:
  name: kong-server-blocks
  namespace: abc

The error is that include fastcgi_params; - since fastcgi is not built into Kong, this is failing here. I have moved on to use an Nginx container on the same pod as the FPM container and I’m sharing the assets with an emptyDir volume mount.