Nginx : host not found in upstream php Kubernetes

development

#1

hai,
i’m new here for kubernetes, so i’ve a question or need solution for this task… how can i deploy nginx and php-fpm with independent service? because i’ve an issue like this one :

root@development:/opt/docker/docker-cucunguk# kubectl logs nginx-7988c74546-gk54v
2018/10/02 15:22:58 [emerg] 1#1: host not found in upstream “php” in /etc/nginx/conf.d/adminer.conf:17
nginx: [emerg] host not found in upstream “php” in /etc/nginx/conf.d/adminer.conf:17

here my yaml of nginx and php .

NGINX

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: nginx
spec:
containers:
- name: cucunguk-nginx
image: images.registry.codigo.id/cucunguk_nginx:0.1
ports:
- containerPort: 80
- containerPort: 443
volumeMounts:
- mountPath: /opt/www
name: project
workingDir: /opt/www
restartPolicy: Always
imagePullSecrets:
- name: regsecret
volumes:
- name: project
persistentVolumeClaim:
claimName: project


apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
ports:

  • name: “80”
    port: 80
    protocol: “TCP”
    targetPort: 80
  • name: “443”
    port: 443
    protocol: “TCP”
    targetPort: 443
    selector:
    io.kompose.service: nginx

PHP

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: php
name: php
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: php
spec:
containers:
- name: cucunguk-php
image: images.registry.codigo.id/cucunguk_php:0.1
ports:
- containerPort: 9000
volumeMounts:
- mountPath: /opt/www
name: project
workingDir: /opt/www
restartPolicy: Always
volumes:
- name: project
persistentVolumeClaim:
claimName: project
imagePullSecrets:
- name: regsecret


apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: php
name: php
spec:
ports:

  • name: “9000”
    port: 9000
    protocol: “TCP”
    targetPort: 9000
    selector:
    io.kompose.service: php

thanks


#2

Host not found says the error you pasted, right?

Have you checked you can connect to the php service from nginx and you have spelled it correctly in the nginx conf?


#3

yes, here my nginx.conf

#ADMINER
server {
server_name adminer.nabilah.net;

root /opt/www/adminer;
index adminer.php index.php index.html;

error_log /var/log/nginx/adminer_error.log;
access_log /var/log/nginx/adminer_access.log;
	
location / {
	try_files $uri $uri/ /index.php?$args;
} 

location ~ \.php$ {
	fastcgi_pass php:9000;
	fastcgi_index index.php;
	include fastcgi_params;
	fastcgi_param PATH_INFO $uri;
	fastcgi_param SCRIPT_FILENAME /opt/www/adminer$fastcgi_script_name;
}

location ~ /\. {
	deny all;
}

}
#FRONTEND
server {
listen 80 default_server;
listen [::]:80 default_server;

root /opt/www;

index index.html index.php;

server_name nabilah.net;

location / {
	try_files $uri $uri/ =404;
}

location ~ \.php$ {
	include fastcgi_params;
            fastcgi_pass php:9000;
            fastcgi_index index.php;
}

location ~ /\. {
	deny all;
}

}


#4

So? Have you checked?


#5

so how do i check it? because pods nginx itself don’t run …

sorry i’m new here … :smiley:


#6

Maybe change the command to a long sleep and attach?

Have you checked the docs already? For example this: https://kubernetes.io/docs/tasks/debug-application-cluster/debug-pod-replication-controller/#debugging-pods


#7

Any particular reason to expose php as service? If not I recommend you to create just one deployment with pods multicontainer (nginx and fpm at least) your nginx upstream will hit fpm on 127.0.0.1:9000 as you defined.