0

Im trying to port a docker-compose configuration to kubernetes but i get "connection refused while connect to upstream ....upstream:fastcgi://127.0.0.1:9000" Containers up and running, service nginx load balancer acessible but mysql and php-fpm not not acessible from nginx container.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app
  name: web
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name : mysql
        env:
          - name: MYSQL_DATABASE
            value: sylius
          - name: MYSQL_PASSWORD
            value: nopassword
          - name: MYSQL_ROOT_PASSWORD
            value: nopassword
          - name: MYSQL_USER
            value: sylius
        image : mysql

        volumeMounts:  
        - mountPath: "/srv/sylius"
          name: www-data
       
        ports:
        - containerPort: 3306
          name: http
          protocol: TCP
        resources: {}
        
          
      - name: sylius-php-fpm
        image: licass/my_sylius_php:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 9000
          name: http
          protocol: TCP
        volumeMounts:
        - name: nginx-config-volume
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: default.conf
        - mountPath: "/srv/sylius"
          name: www-data

      - name: sylius-node
        image: licass/my_sylius_node
        imagePullPolicy: Always
        command: [ "sleep" ]
        args: [ "infinity" ]
        volumeMounts:  
        - mountPath: "/srv/sylius"
          name: www-data

      - name: nginx
        image: nginx:alpine
        imagePullPolicy: Always
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
        volumeMounts:
        - name: nginx-config-volume
          mountPath: /etc/nginx/conf.d/default.conf
          subPath: default.conf
        - mountPath: "/srv/sylius"
          name: www-data
      restartPolicy: Always
      serviceAccountName: ""
      
      initContainers:
      - name: git-cloner
        image: alpine/git
        args:
            - clone
            - --single-branch
            - --
            - https://github.com/Sylius/Sylius-Standard.git
            - /data
        volumeMounts:
        - mountPath: /data
          name: www-data
      
      volumes:         
      - name: nginx-config-volume
        configMap:
          name: nginx-config
      - name: www-data
        emptyDir: {}   

Im just starting with kubernetes and acnnot figure how to network inside pod . Thanks in advance.

Leonel Matias Domingos
  • 1,922
  • 5
  • 29
  • 53
  • You almost always would want to run these as separate pods (a Deployment each for the Node, PHP, and Nginx components; a StatefulSet for the MySQL database; and an out-of-cluster CI system that can build and push immutable images). In this architecture if you need to change anything in the PHP code you need to delete and recreate the entire set of containers, which is far more disruptive than required. – David Maze May 13 '21 at 12:28
  • You rigth David. But at the moment i just want to do the networking and learn k8s . baby steps towards event driven system – Leonel Matias Domingos May 14 '21 at 05:25
  • You rigth David. But at the moment i just want to do the networking and learn k8s . baby steps towards event driven system. About CI , i really have problems with Composer and yarn builds/installs that will be adressed by this. One app for each pod ...database will be a managed service – Leonel Matias Domingos May 14 '21 at 05:34

1 Answers1

0

As documented here:

Inside a Pod (and only then), the containers that belong to the Pod can communicate with one another using localhost

Wytrzymały Wiktor
  • 11,492
  • 5
  • 29
  • 37
Leonel Matias Domingos
  • 1,922
  • 5
  • 29
  • 53
  • The poster has shown YAML that shows there are multiple containers in the pod, therefore this comment isn't appropriate. – GrahamB Mar 11 '22 at 17:59