Kubernetes single node cluster: dns not working after deploy new image

11/21/2020

I am beginner in Kubernetes. I have testing VPS with Kubernetes cluster, deployed one pod with nginx and configuration:

fastcgi_pass php-fpm:9000;

...and one pod with php-fpm, service for php-fpm and nginx.

Everything works, but when I deploy new image php-fpm, pod recreating and running but nginx cannot resolv php-fpm.

Deploy new image:

kubectl apply -f php_deployment.yaml <- with new image version

This is my configs:

Nginx Dockerfile:

FROM nginx:alpine

WORKDIR /var/www

CMD ["nginx"]

COPY ./docker/nginx/nginx.conf /etc/nginx/nginx.conf
COPY ./docker/nginx/sites-available/ /etc/nginx/sites-available

COPY ./src/public /var/www/public

EXPOSE 80 443

PHP-FPM Dockerfile:

FROM php:7.4-fpm-alpine

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/

RUN curl -sS https://getcomposer.org/composer-1.phar -o /usr/bin/composer && chmod 700 /usr/bin/composer

RUN apk --update --no-cache add vim bash

RUN install-php-extensions pdo_pgsql http

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY ./src/ /var/www/

WORKDIR /var/www

CMD composer install ; php-fpm

EXPOSE 9000

Kubernetes - php_deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: php-fpm
  labels:
    app: php-fpm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: php-fpm
  template:
    metadata:
      labels:
        app: php-fpm
    spec:
      containers:
      - name: php-fpm
        image: kdosiodjinud/php-fpm:2.0.6
        imagePullPolicy: Always
        ports:
          - containerPort: 9000

Kubernetes php_service.yaml

apiVersion: v1
kind: Service
metadata:
  name: php-fpm
spec:
  selector:
    app: php-fpm
  ports:
  - protocol: TCP
    port: 9000
    targetPort: 9000

Kubernetes nginx_deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: kdosiodjinud/nginx:2.0.3
        imagePullPolicy: Always
        ports:
          - containerPort: 80

Kubernetes nginx_service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort:  80

I test funkcionality from local with kubectl proxy: http://localhost:8001/api/v1/namespaces/default/services/http:nginx:/proxy/#!/

Kubernetes kubectl get pods -A

NAMESPACE              NAME                                                           READY   STATUS    RESTARTS   AGE
default                nginx-84c6ffb78d-srsvn                                         1/1     Running   3          43m
default                php-fpm-5984c4bb56-5rf8v                                       1/1     Running   1          43m
default                postgres-7ffd788bc9-58z7k                                      1/1     Running   11         25h
kube-system            canal-fd6s4                                                    2/2     Running   22         27h
kube-system            coredns-659dc8dcb5-4wv2m                                       1/1     Running   1          45m
kube-system            coredns-659dc8dcb5-sshtt                                       1/1     Running   1          45m
kube-system            etcd-onekube-ip-89-221-220-50.localdomain                      1/1     Running   11         27h
kube-system            kube-apiserver-onekube-ip-89-221-220-50.localdomain            1/1     Running   13         27h
kube-system            kube-controller-manager-onekube-ip-89-221-220-50.localdomain   1/1     Running   11         27h
kube-system            kube-proxy-r84vz                                               1/1     Running   11         27h
kube-system            kube-scheduler-onekube-ip-89-221-220-50.localdomain            1/1     Running   11         27h
kubernetes-dashboard   dashboard-metrics-scraper-694557449d-dc6mp                     1/1     Running   12         27h
kubernetes-dashboard   kubernetes-dashboard-9774cc786-7cgtr                           1/1     Running   11         27h

Kubernetes kubectl get svc -A

NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
default                kubernetes                  ClusterIP   10.96.0.1        <none>        443/TCP                  27h
default                kubernetes-dashboard        ClusterIP   10.103.115.236   <none>        443/TCP                  25h
default                nginx                       ClusterIP   10.111.150.200   <none>        80/TCP                   26h
default                php-fpm                     ClusterIP   10.100.87.2      <none>        9000/TCP                 26h
default                postgres                    ClusterIP   10.107.164.67    <none>        5432/TCP                 25h
kube-system            kube-dns                    ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP,9153/TCP   27h
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.103.202.94    <none>        8000/TCP                 27h
kubernetes-dashboard   kubernetes-dashboard        ClusterIP   10.102.77.2      <none>        443/TCP                  27h

Images are public: kdosiodjinud/nginx:2.0.3 kdosiodjinud/php-fpm:2.0.6 and kdosiodjinud/php-fpm:2.0.7 (same images with miniedit in app source, I use switch for test this case)

If more information is needed, I will be happy to add it :)

Thank you for the advice

-- KdoSiOdJinud
kubernetes

0 Answers