Google容器引擎中的pod如何相互通信/链接

时间:2016-06-10 14:28:16

标签: docker kubernetes google-kubernetes-engine

我在这个例子中喋喋不休:https://cloud.google.com/container-engine/docs/tutorials/persistent-disk/

我的修改: - 我正在使用自己的Wordpress图像[x]工作

服务启动(它需要更多的CPU 0.8而不是0.5,但现在它可以工作)

  • 我想使用mariadb代替mysql []失败!

我无法弄清楚两个豆荚如何连在一起!!!! 〜5h +仍然失败

这是我的.yaml-Files

apiVersion: v1
kind: Pod
metadata:
  name: wpsite
  labels:
    name: wpsite
spec:
  containers:
    - image: <my image on gcr.io>
      name: wpsite

      env:
        - name: WORDPRESS_DB_PASSWORD
          # Change this - must match mysql.yaml password.
          value: example
      ports:
        - containerPort: 80
          name: wpsite

      volumeMounts:
          # Name must match the volume name below.
        - name: wpsite-disk
          # Mount path within the container.
          mountPath: /var/www/html

  volumes:
    - name: wpsite-disk
      gcePersistentDisk:
        # This GCE persistent disk must already exist.
        pdName: wpsite-disk
        fsType: ext4

服务:

apiVersion: v1
kind: Service
metadata:
  labels:
    name: wpsite
  name: wpsite
spec:
  type: LoadBalancer
  ports:
    # The port that this service should serve on.
    - port: 80
      targetPort: 80
      protocol: TCP

  # Label keys and values that must match in order to receive traffic for this service.
  selector:
    name: wpsite

MariaDB的:

apiVersion: v1
kind: Pod
metadata:
  name: mariadb
  labels:
    name: mariadb
spec:
  containers:
    - resources:
        limits:
          # 0.5 hat nicht funktioniert
          # Fehlermeldung in: kubectl describe pod mariadb
          cpu: 0.8

      image: mariadb:10.1
      name: mariadb
      env:
        - name: MYSQL_ROOT_PASSWORD
          # Change this password!
          value: example

      ports:
        - containerPort: 3306
          name: mariadb

      volumeMounts:
          # This name must match the volumes.name below.
        - name: mariadb-persistent-storage
          mountPath: /var/lib/mysql
  volumes:
    - name: mariadb-persistent-storage
      gcePersistentDisk:
        # This disk must already exist.
        pdName: mariadb-disk
        fsType: ext4

玛利亚-DB-服务:

apiVersion: v1
kind: Service
metadata:
  labels:
    name: mariadb
  name: mariadb
spec:
  ports:
    # The port that this service should serve on.
    - port: 3306

  # Label keys and values that must match in
  # order to receive traffic for this service.
  selector:
    name: mysql

kubectl logs wpsite显示如下错误消息:Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 10

1 个答案:

答案 0 :(得分:0)

好的 - 发现了!

这是mariadb-service.yaml中的名字 metadata.name必须是mysql而不是mariadb,mariadb-service中的选择器必须指向mariadb(pod)

以下是工作文件:

mariadb.yaml

apiVersion: v1
kind: Pod

metadata:
  name: mariadb

  labels:
    name: mariadb
spec:
  containers:
    - resources:
        limits:
          # 0.5 hat nicht funktioniert
          # Fehlermeldung in: kubectl describe pod mariadb
          cpu: 0.8

      image: mariadb:10.1
      name: mariadb
      env:
        - name: MYSQL_ROOT_PASSWORD
          # Change this password!
          value: example

      ports:
        - containerPort: 3306
          name: mariadb

      volumeMounts:
          # This name must match the volumes.name below.
        - name: mariadb-persistent-storage
          mountPath: /var/lib/mysql
  volumes:
    - name: mariadb-persistent-storage
      gcePersistentDisk:
        # This disk must already exist.
        pdName: mariadb-disk
        fsType: ext4

MariaDB的-service.yaml

apiVersion: v1
kind: Service

metadata:
  name: mysql

  labels:
    name: mysql
spec:
  ports:
    # The port that this service should serve on.
    - port: 3306

  # Label keys and values that must match in
  # order to receive traffic for this service.
  selector:
    name: mariadb

wpsite.yaml

apiVersion: v1
kind: Pod

metadata:
  name: wpsite

  labels:
    name: wpsite
spec:
  containers:
    - image: <change this to your imagename on gcr.io>
      name: wpsite

      env:
        - name: WORDPRESS_DB_PASSWORD
          # Change this - must match mysql.yaml password.
          value: example
      ports:
        - containerPort: 80
          name: wpsite

      volumeMounts:
          # Name must match the volume name below.
        - name: wpsite-disk
          # Mount path within the container.
          mountPath: /var/www/html

  volumes:
    - name: wpsite-disk
      gcePersistentDisk:
        # This GCE persistent disk must already exist.
        pdName: wpsite-disk
        fsType: ext4

wpsite-service.yaml

apiVersion: v1
kind: Service

metadata:
  name: wpsite

  labels:
    name: wpsite
spec:
  type: LoadBalancer
  ports:
    # The port that this service should serve on.
    - port: 80
      targetPort: 80
      protocol: TCP

  # Label keys and values that must match in order to receive traffic for this service.
  selector:
    name: wpsite

使用这些设置我运行:(我的yaml文件在gke下)

$ kubectl create -f gke/mariadb.yaml

# Check
$ kubectl get pod

$ kubectl create -f gke/mariadb-service.yaml

# Check 
$ kubectl get service mysql!!!! (name in mariadb = mysql)

$ kubectl create -f gke/wpsite.yaml

# Check
$ kubectl get pod

$ kubectl create -f gke/wpsite-service.yaml

# Check
$ kubectl describe service wpsite

希望这有助于某人...