多容器 pod 中的连接被拒绝

问题描述

我正在尝试将 docker-compose 配置移植到 kubernetes,但我得到“connection refused while connect to upstream ....upstream:fastcgi://127.0.0.1:9000” 容器启动并运行,服务 Nginx 负载均衡器可访问,但 MysqLPHP-fpm 不可从 Nginx 容器访问。

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: {}   

我刚开始使用 kubernetes 并且不知道如何在 pod 内联网。 提前致谢。

解决方法

如记录here

在 Pod 内部(并且只有这样),属于 Pod 的容器 可以使用本地主机相互通信