1

I am not able to run both apache (httpd) and nginx in the same pod. Indeed both containers are running on port 80.

# kubectl logs -f multi-container -c apache
(98)Address in use: AH00072: make_sock: could not bind to address [::]:80

I visited the home page of nginx in dockerhub and I noticed the environment variable NGINX_PORT, I set it to 81 and I changed containerPort to 81 as well. Even though, the nginx is still running on port 80.

# kubectl exec -it multi-container -c nginx -- nc -zv localhost 80
localhost (127.0.0.1:80) open

# kubectl exec -it multi-container -c nginx -- nc -zv localhost 81
command terminated with exit code 1

In addition, the env variable inside the container is correct:

# kubectl exec -it multi-container -c nginx -- env | grep NGINX_PORT=

NGINX_PORT=81

This my pod definition:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: multi-container
  name: multi-container
spec:
  containers:
  - image: nginx:alpine
    name: nginx
    ports:
      - containerPort: 81
    env:
      - name: NGINX_PORT
        value: "81"

  - image: httpd:alpine
    name: apache
    ports:
      - containerPort: 80
  dnsPolicy: ClusterFirst
  restartPolicy: Always

Without making nginx as reverse proxy to httpd, how to make two containers running separately on different ports. Should I customize its images and build new ones?

1
  • Please describe what you are trying to achieve. Could you explain why you are trying to run both nginx and httpd in one POD?
    – 030
    Dec 24, 2019 at 14:52

0

Browse other questions tagged or ask your own question.