From 284cd205d2e2e96c011b4c530e492418872054de Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Wed, 6 May 2015 15:14:16 -0700 Subject: [PATCH] update mysql-wordpress example to use v1beta3 API --- examples/mysql-wordpress-pd/README.md | 187 +++++++++--------- .../mysql-wordpress-pd/mysql-service.yaml | 24 ++- examples/mysql-wordpress-pd/mysql.yaml | 61 +++--- .../v1beta3/mysql-service.yaml | 13 -- .../mysql-wordpress-pd/v1beta3/mysql.yaml | 40 ---- .../v1beta3/wordpress-service.yaml | 13 -- .../mysql-wordpress-pd/v1beta3/wordpress.yaml | 37 ---- .../mysql-wordpress-pd/wordpress-service.yaml | 25 ++- examples/mysql-wordpress-pd/wordpress.yaml | 57 +++--- 9 files changed, 169 insertions(+), 288 deletions(-) delete mode 100644 examples/mysql-wordpress-pd/v1beta3/mysql-service.yaml delete mode 100644 examples/mysql-wordpress-pd/v1beta3/mysql.yaml delete mode 100644 examples/mysql-wordpress-pd/v1beta3/wordpress-service.yaml delete mode 100644 examples/mysql-wordpress-pd/v1beta3/wordpress.yaml diff --git a/examples/mysql-wordpress-pd/README.md b/examples/mysql-wordpress-pd/README.md index d2cdc42c451..404257d77de 100644 --- a/examples/mysql-wordpress-pd/README.md +++ b/examples/mysql-wordpress-pd/README.md @@ -22,7 +22,13 @@ Then, set the gcloud default project name to point to the project you want to us gcloud config set project ``` -Next, grab the Kubernetes [release binary](https://github.com/GoogleCloudPlatform/kubernetes/releases). You can do this via: +Next, grab the Kubernetes [release binary](https://github.com/GoogleCloudPlatform/kubernetes/releases) and start up a Kubernetes cluster: +``` +$ /cluster/kube-up.sh +``` +where `` is the path to your Kubernetes installation. + +Or, as [described here](http://docs.k8s.io/getting-started-guides/gce.md), you can do this via: ```shell wget -q -O - https://get.k8s.io | bash ``` @@ -31,14 +37,6 @@ or curl -sS https://get.k8s.io | bash ``` -Then, start up a Kubernetes cluster as [described here](http://docs.k8s.io/getting-started-guides/gce.md). - -``` -$ /cluster/kube-up.sh -``` - -where `` is the path to your Kubernetes installation. - ## Create two persistent disks For this WordPress installation, we're going to configure our Kubernetes [pods](http://docs.k8s.io/pods.md) to use [persistent disks](https://cloud.google.com/compute/docs/disks). This means that we can preserve installation state across pod shutdown and re-startup. @@ -69,37 +67,38 @@ First, **edit `mysql.yaml`**, the mysql pod definition, to use a database passwo `mysql.yaml` looks like this: ```yaml -apiVersion: v1beta1 -id: mysql -desiredState: - manifest: - version: v1beta1 - id: mysql - containers: - - name: mysql - image: mysql - env: - - name: MYSQL_ROOT_PASSWORD - # change this - value: yourpassword - cpu: 100 - ports: - - containerPort: 3306 - volumeMounts: - # name must match the volume name below - - name: mysql-persistent-storage - # mount path within the container - mountPath: /var/lib/mysql - volumes: - - name: mysql-persistent-storage - source: - persistentDisk: - # This GCE PD must already exist - pdName: mysql-disk - fsType: ext4 -labels: - name: mysql +apiVersion: v1beta3 kind: Pod +metadata: + name: mysql + labels: + name: mysql +spec: + containers: + - resources: + limits : + cpu: 1 + image: mysql + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + # change this + value: yourpassword + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + # name must match the volume name below + - name: mysql-persistent-storage + # mount path within the container + mountPath: /var/lib/mysql + volumes: + - name: mysql-persistent-storage + gcePersistentDisk: + # This GCE PD must already exist. + pdName: mysql-disk + fsType: ext4 + ``` Note that we've defined a volume mount for `/var/lib/mysql`, and specified a volume that uses the persistent disk (`mysql-disk`) that you created. @@ -130,28 +129,26 @@ If you want to do deeper troubleshooting, e.g. if it seems a container is not st ### Start the Mysql service We'll define and start a [service](http://docs.k8s.io/services.md) that lets other pods access the mysql database on a known port and host. -We will specifically name the service `mysql`. This will let us leverage the support for [Docker-links-compatible](http://docs.k8s.io/services.md#how-do-they-work) service environment variables when we up the wordpress pod. The wordpress Docker image expects to be linked to a mysql container named `mysql`, as you can see in the "How to use this image" section on the wordpress docker hub [page](https://registry.hub.docker.com/_/wordpress/). +We will specifically name the service `mysql`. This will let us leverage the support for [Docker-links-compatible](http://docs.k8s.io/services.md#how-do-they-work) service environment variables when we set up the wordpress pod. The wordpress Docker image expects to be linked to a mysql container named `mysql`, as you can see in the "How to use this image" section on the wordpress docker hub [page](https://registry.hub.docker.com/_/wordpress/). So if we label our Kubernetes mysql service `mysql`, the wordpress pod will be able to use the Docker-links-compatible environment variables, defined by Kubernetes, to connect to the database. The `mysql-service.yaml` file looks like this: ```yaml +apiVersion: v1beta3 kind: Service -apiVersion: v1beta1 -id: mysql -# the port that this service should serve on -port: 3306 -# just like the selector in the replication controller, -# but this time it identifies the set of pods to load balance -# traffic to. -selector: - name: mysql -# the container on each pod to connect to, can be a name -# (e.g. 'www') or a number (e.g. 80) -containerPort: 3306 -labels: +metadata: + labels: + name: mysql 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: mysql ``` Start the service like this: @@ -174,37 +171,34 @@ Once the mysql service is up, start the wordpress pod, specified in Note that this config file also defines a volume, this one using the `wordpress-disk` persistent disk that you created. ```yaml -apiVersion: v1beta1 -id: wordpress -desiredState: - manifest: - version: v1beta1 - id: frontendController - containers: - - name: wordpress - image: wordpress - ports: - - containerPort: 80 - volumeMounts: - # name must match the volume name below - - name: wordpress-persistent-storage - # mount path within the container - mountPath: /var/www/html - env: - - name: WORDPRESS_DB_PASSWORD - # change this - must match mysql.yaml password - value: yourpassword - volumes: - - name: wordpress-persistent-storage - source: - # emptyDir: {} - persistentDisk: - # This GCE PD must already exist - pdName: wordpress-disk - fsType: ext4 -labels: - name: wpfrontend +apiVersion: v1beta3 kind: Pod +metadata: + name: wordpress + labels: + name: wordpress +spec: + containers: + - image: wordpress + name: wordpress + env: + - name: WORDPRESS_DB_PASSWORD + # change this - must match mysql.yaml password + value: yourpassword + ports: + - containerPort: 80 + name: wordpress + volumeMounts: + # name must match the volume name below + - name: wordpress-persistent-storage + # mount path within the container + mountPath: /var/www/html + volumes: + - name: wordpress-persistent-storage + gcePersistentDisk: + # This GCE PD must already exist. + pdName: wordpress-disk + fsType: ext4 ``` Create the pod: @@ -227,26 +221,23 @@ Once the wordpress pod is running, start its service, specified by `wordpress-se The service config file looks like this: ```yaml +apiVersion: v1beta3 kind: Service -apiVersion: v1beta1 -id: wpfrontend -# the port that this service should serve on. -port: 80 -# just like the selector in the replication controller, -# but this time it identifies the set of pods to load balance -# traffic to. -selector: +metadata: + labels: + name: wpfrontend name: wpfrontend -# the container on each pod to connect to, can be a name -# (e.g. 'www') or a number (e.g. 80) -containerPort: 80 -labels: - name: wpfrontend -createExternalLoadBalancer: true +spec: + createExternalLoadBalancer: true + ports: + # the port that this service should serve on + - port: 80 + # label keys and values that must match in order to receive traffic for this service + selector: + name: wordpress ``` Note the `createExternalLoadBalancer` setting. This will set up the wordpress service behind an external IP. -`createExternalLoadBalancer` only works on GCE. Note also that we've set the service port to 80. We'll return to that shortly. Start the service: diff --git a/examples/mysql-wordpress-pd/mysql-service.yaml b/examples/mysql-wordpress-pd/mysql-service.yaml index 9ebcb4854ee..c8e0c55a18f 100644 --- a/examples/mysql-wordpress-pd/mysql-service.yaml +++ b/examples/mysql-wordpress-pd/mysql-service.yaml @@ -1,15 +1,13 @@ +apiVersion: v1beta3 kind: Service -apiVersion: v1beta1 -id: mysql -# the port that this service should serve on -port: 3306 -# just like the selector in the replication controller, -# but this time it identifies the set of pods to load balance -# traffic to. -selector: - name: mysql -# the container on each pod to connect to, can be a name -# (e.g. 'www') or a number (e.g. 80) -containerPort: 3306 -labels: +metadata: + labels: + name: mysql 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: mysql diff --git a/examples/mysql-wordpress-pd/mysql.yaml b/examples/mysql-wordpress-pd/mysql.yaml index aa4b2a2ed35..25af30388c4 100644 --- a/examples/mysql-wordpress-pd/mysql.yaml +++ b/examples/mysql-wordpress-pd/mysql.yaml @@ -1,32 +1,31 @@ -apiVersion: v1beta1 -id: mysql -desiredState: - manifest: - version: v1beta1 - id: mysql - containers: - - name: mysql - image: mysql - env: - - name: MYSQL_ROOT_PASSWORD - # change this - value: yourpassword - cpu: 100 - ports: - - containerPort: 3306 - volumeMounts: - # name must match the volume name below - - name: mysql-persistent-storage - # mount path within the container - mountPath: /var/lib/mysql - volumes: - - name: mysql-persistent-storage - source: - # emptyDir: {} - persistentDisk: - # This GCE PD must already exist. - pdName: mysql-disk - fsType: ext4 -labels: - name: mysql +apiVersion: v1beta3 kind: Pod +metadata: + name: mysql + labels: + name: mysql +spec: + containers: + - resources: + limits : + cpu: 1 + image: mysql + name: mysql + env: + - name: MYSQL_ROOT_PASSWORD + # change this + value: yourpassword + ports: + - containerPort: 3306 + name: mysql + volumeMounts: + # name must match the volume name below + - name: mysql-persistent-storage + # mount path within the container + mountPath: /var/lib/mysql + volumes: + - name: mysql-persistent-storage + gcePersistentDisk: + # This GCE PD must already exist. + pdName: mysql-disk + fsType: ext4 diff --git a/examples/mysql-wordpress-pd/v1beta3/mysql-service.yaml b/examples/mysql-wordpress-pd/v1beta3/mysql-service.yaml deleted file mode 100644 index 9848475d4ab..00000000000 --- a/examples/mysql-wordpress-pd/v1beta3/mysql-service.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1beta3 -kind: Service -metadata: - labels: - name: mysql - name: mysql -spec: - ports: - - port: 3306 - targetPort: 3306 - selector: - name: mysql - diff --git a/examples/mysql-wordpress-pd/v1beta3/mysql.yaml b/examples/mysql-wordpress-pd/v1beta3/mysql.yaml deleted file mode 100644 index 5361c281ed5..00000000000 --- a/examples/mysql-wordpress-pd/v1beta3/mysql.yaml +++ /dev/null @@ -1,40 +0,0 @@ -apiVersion: v1beta3 -kind: ReplicationController -metadata: - labels: - name: mysql - name: mysql -spec: - replicas: 1 - selector: - name: mysql - template: - metadata: - labels: - name: mysql - spec: - containers: - - resources: - limits : - cpu: 1 - image: mysql - name: mysql - env: - - name: MYSQL_ROOT_PASSWORD - # change this - value: yourpassword - ports: - - containerPort: 3306 - name: mysql - volumeMounts: - # name must match the volume name below - - name: mysql-persistent-storage - # mount path within the container - mountPath: /var/lib/mysql - volumes: - - name: mysql-persistent-storage - gcePersistentDisk: - # This GCE PD must already exist. - pdName: mysql-disk - fsType: ext4 - diff --git a/examples/mysql-wordpress-pd/v1beta3/wordpress-service.yaml b/examples/mysql-wordpress-pd/v1beta3/wordpress-service.yaml deleted file mode 100644 index a2aa333faf8..00000000000 --- a/examples/mysql-wordpress-pd/v1beta3/wordpress-service.yaml +++ /dev/null @@ -1,13 +0,0 @@ -apiVersion: v1beta3 -kind: Service -metadata: - labels: - name: wpfrontend - name: wpfrontend -spec: - ports: - - port: 80 - targetPort: 80 - selector: - name: wpfrontend - diff --git a/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml b/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml deleted file mode 100644 index 24efa993407..00000000000 --- a/examples/mysql-wordpress-pd/v1beta3/wordpress.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: v1beta3 -kind: ReplicationController -metadata: - labels: - name: wordpress - name: wordpress -spec: - replicas: 1 - selector: - name: wordpress - template: - metadata: - labels: - name: wordpress - spec: - containers: - - image: wordpress - name: wordpress - env: - - name: WORDPRESS_DB_PASSWORD - # change this - must match mysql.yaml password - value: yourpassword - ports: - - containerPort: 80 - name: wordpress - volumeMounts: - # name must match the volume name below - - name: wordpress-persistent-storage - # mount path within the container - mountPath: /var/www/html - volumes: - - name: wordpress-persistent-storage - gcePersistentDisk: - # This GCE PD must already exist. - pdName: wordpress-disk - fsType: ext4 - diff --git a/examples/mysql-wordpress-pd/wordpress-service.yaml b/examples/mysql-wordpress-pd/wordpress-service.yaml index 7a9f0e8a700..3a8573d1097 100644 --- a/examples/mysql-wordpress-pd/wordpress-service.yaml +++ b/examples/mysql-wordpress-pd/wordpress-service.yaml @@ -1,15 +1,14 @@ +apiVersion: v1beta3 kind: Service -apiVersion: v1beta1 -id: wpfrontend -# the port that this service should serve on -port: 80 -# identifies the set of pods to load balance -# traffic to. -selector: +metadata: + labels: + name: wpfrontend name: wpfrontend -# the container on each pod to connect to, can be a name -# (e.g. 'www') or a number (e.g. 80) -containerPort: 80 -labels: - name: wpfrontend -createExternalLoadBalancer: true +spec: + createExternalLoadBalancer: true + ports: + # the port that this service should serve on + - port: 80 + # label keys and values that must match in order to receive traffic for this service + selector: + name: wordpress diff --git a/examples/mysql-wordpress-pd/wordpress.yaml b/examples/mysql-wordpress-pd/wordpress.yaml index decf8ca6664..56230ab3710 100644 --- a/examples/mysql-wordpress-pd/wordpress.yaml +++ b/examples/mysql-wordpress-pd/wordpress.yaml @@ -1,31 +1,28 @@ -apiVersion: v1beta1 -id: wordpress -desiredState: - manifest: - version: v1beta1 - id: wordpress - containers: - - name: wordpress - image: wordpress - ports: - - containerPort: 80 - volumeMounts: - # name must match the volume name below - - name: wordpress-persistent-storage - # mount path within the container - mountPath: /var/www/html - env: - - name: WORDPRESS_DB_PASSWORD - # change this - must match mysql.yaml password - value: yourpassword - volumes: - - name: wordpress-persistent-storage - source: - # emptyDir: {} - persistentDisk: - # This GCE PD must already exist. - pdName: wordpress-disk - fsType: ext4 -labels: - name: wpfrontend +apiVersion: v1beta3 kind: Pod +metadata: + name: wordpress + labels: + name: wordpress +spec: + containers: + - image: wordpress + name: wordpress + env: + - name: WORDPRESS_DB_PASSWORD + # change this - must match mysql.yaml password + value: yourpassword + ports: + - containerPort: 80 + name: wordpress + volumeMounts: + # name must match the volume name below + - name: wordpress-persistent-storage + # mount path within the container + mountPath: /var/www/html + volumes: + - name: wordpress-persistent-storage + gcePersistentDisk: + # This GCE PD must already exist. + pdName: wordpress-disk + fsType: ext4