2016-06-10 42 views
0

我用這個例子反覆折騰:https://cloud.google.com/container-engine/docs/tutorials/persistent-disk/如何在谷歌集裝箱引擎通話/鏈接做莢彼此

我的修改: - 我用我自己的WordPress圖像[X]作品

服務(它需要更多的CPU 0.8而不是0.5,但現在它的工作原理)

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

我想不出兩個吊艙是如何連接在一起的!仍然未能

這裏〜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 

MariaDB的服務:

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日誌wpsite顯示如下的錯誤消息:Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 10

回答

0

確定 - 找到它了!

它在MariaDB的-service.yaml名 metadata.name必須是mysql和不MariaDB的,在MariaDB的服務選擇必須指向MariaDB的(莢)

這裏是工作文件:

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 

希望這可以幫助別人...

相關問題