Kubernetes PHP NGINX Pods Intercommunication

12/21/2019

I'm running a 3-master and 3-worker cluster, trying to communicate pods from php-fpm service with pods from nginx-service, have changed even CNI from Calico to Weave but the problem persists, any help would be great. Inside my nginx config I have:

            location ~ \.php$ {
            root           /var/www/html;
            fastcgi_pass   php:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_read_timeout 300;
        }

So I expect to get php-fpm service by name "php:9000". And here is my deployments and services cfg:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
spec:
  selector:
    matchLabels:
      component: web
  replicas: 9
  template:
    metadata:
      labels:
        component: web
    spec:
      containers:
      - name: web
        image: docker-registry.vetorial.net/gponapi-nginx
        ports:
        - containerPort: 80
      imagePullSecrets:
        - name: regcred
---
apiVersion: v1
kind: Service
metadata:
  name: web
  labels:
    component: web
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    component: web
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: php
spec:
  selector:
    matchLabels:
      component: php
  replicas: 9
  template:
    metadata:
      labels:
        component: php
    spec:
      containers:
      - name: php
        image: docker-registry.vetorial.net/gponapi-php
        ports:
        - containerPort: 9000
      imagePullSecrets:
        - name: regcred
---
apiVersion: v1
kind: Service
metadata:
  name: php
spec:
  type: ClusterIP
  selector:
    component: php
  ports:
  - port: 9000
    targetPort: 9000

And the error that I`m geting:

2019/12/21 12:54:25 [emerg] 1#1: host not found in upstream "php" in /etc/nginx/nginx.conf:52
nginx: [emerg] host not found in upstream "php" in /etc/nginx/nginx.conf:52

There is something wrong with my deployments and services cfg?

EDIT:

Trying to debug DNS I see that pods are trying to resolve names in inherited DNS from host:

[ root@k8-master-01  >  ~/gponApi ] kubectl exec -ti busybox -- nslookup kubernetes.default
Server:    10.96.0.10
Address 1: 10.96.0.10

[ root@k8-master-01  >  ~/gponApi ] for p in $(kubectl get pods --namespace=kube-system -l k8s-app=kube-dns -o name); do kubectl logs --namespace=kube-system $p; done
.:53
[INFO] plugin/reload: Running configuration MD5 = 4e235fcc3696966e76816bcd9034ebc7
CoreDNS-1.6.5
linux/amd64, go1.13.4, c2fd1b2
[INFO] Reloading
[INFO] plugin/health: Going into lameduck mode for 5s
[INFO] plugin/reload: Running configuration MD5 = a4809ab99f6713c362194263016e6fac
[INFO] Reloading complete
[INFO] 127.0.0.1:60092 - 22335 "HINFO IN 6654671708538411669.1329448889047522534. udp 57 false 512" NOERROR - 0 4.001984467s
[ERROR] plugin/errors: 2 6654671708538411669.1329448889047522534. HINFO: read udp 10.32.0.4:37293->187.86.128.99:53: read: no route to host
-- Pedro PILLA
kubernetes

1 Answer

12/23/2019

It was firewalld, after disabling it everything works as expected.

-- Pedro PILLA
Source: StackOverflow