【问题标题】:How do pods in Google Container Engine talk/link to each otherGoogle Container Engine 中的 pod 如何相互通信/链接
【发布时间】:2016-06-10 14:28:15
【问题描述】:

我摆弄这个例子:https://cloud.google.com/container-engine/docs/tutorials/persistent-disk/

我的修改: - 我正在使用我自己的 Wordpress 图片 [x] Works

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

  • 我想使用 mariadb 而不是 mysql [ ] 失败!

我无法弄清楚两个 pod 是如何连接在一起的!!!! ~5h + 仍然失败

这是我的 .yaml 文件

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

maria-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

【问题讨论】:

    标签: docker kubernetes google-kubernetes-engine


    【解决方案1】:

    好的 - 找到了!

    这是 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
    

    希望这对某人有所帮助...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2016-08-31
      • 2018-01-01
      • 2017-12-03
      • 1970-01-01
      相关资源
      最近更新 更多