多容器 pod 中的连接被拒绝

时间:2021-05-13 04:36:15

标签: kubernetes networking webserver fpm

我正在尝试将 docker-compose 配置移植到 kubernetes,但我得到“connection refused while connect to upstream ....upstream:fastcgi://127.0.0.1:9000” 容器启动并运行,服务 nginx 负载均衡器可访问,但 mysql 和 php-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 内联网。 提前致谢。

1 个答案:

答案 0 :(得分:1)

如记录here

<块引用>

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