mirror of https://github.com/k3s-io/k3s
Merge pull request #7864 from caesarxuchao/wordpress-example
update mysql-wordpress example to use v1beta3 APIpull/6/head
commit
c41982dac5
|
@ -22,7 +22,13 @@ Then, set the gcloud default project name to point to the project you want to us
|
||||||
gcloud config set project <project-name>
|
gcloud config set project <project-name>
|
||||||
```
|
```
|
||||||
|
|
||||||
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:
|
||||||
|
```
|
||||||
|
$ <kubernetes>/cluster/kube-up.sh
|
||||||
|
```
|
||||||
|
where `<kubernetes>` 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
|
```shell
|
||||||
wget -q -O - https://get.k8s.io | bash
|
wget -q -O - https://get.k8s.io | bash
|
||||||
```
|
```
|
||||||
|
@ -31,14 +37,6 @@ or
|
||||||
curl -sS https://get.k8s.io | bash
|
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).
|
|
||||||
|
|
||||||
```
|
|
||||||
$ <kubernetes>/cluster/kube-up.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
where `<kubernetes>` is the path to your Kubernetes installation.
|
|
||||||
|
|
||||||
## Create two persistent disks
|
## 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.
|
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:
|
`mysql.yaml` looks like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1beta1
|
apiVersion: v1beta3
|
||||||
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
|
|
||||||
kind: Pod
|
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.
|
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
|
### 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'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.
|
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:
|
The `mysql-service.yaml` file looks like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
apiVersion: v1beta3
|
||||||
kind: Service
|
kind: Service
|
||||||
apiVersion: v1beta1
|
metadata:
|
||||||
id: mysql
|
labels:
|
||||||
# the port that this service should serve on
|
name: mysql
|
||||||
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:
|
|
||||||
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:
|
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.
|
Note that this config file also defines a volume, this one using the `wordpress-disk` persistent disk that you created.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1beta1
|
apiVersion: v1beta3
|
||||||
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
|
|
||||||
kind: Pod
|
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:
|
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:
|
The service config file looks like this:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
apiVersion: v1beta3
|
||||||
kind: Service
|
kind: Service
|
||||||
apiVersion: v1beta1
|
metadata:
|
||||||
id: wpfrontend
|
labels:
|
||||||
# the port that this service should serve on.
|
name: wpfrontend
|
||||||
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:
|
|
||||||
name: wpfrontend
|
name: wpfrontend
|
||||||
# the container on each pod to connect to, can be a name
|
spec:
|
||||||
# (e.g. 'www') or a number (e.g. 80)
|
createExternalLoadBalancer: true
|
||||||
containerPort: 80
|
ports:
|
||||||
labels:
|
# the port that this service should serve on
|
||||||
name: wpfrontend
|
- port: 80
|
||||||
createExternalLoadBalancer: true
|
# 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.
|
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.
|
Note also that we've set the service port to 80. We'll return to that shortly.
|
||||||
|
|
||||||
Start the service:
|
Start the service:
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
|
apiVersion: v1beta3
|
||||||
kind: Service
|
kind: Service
|
||||||
apiVersion: v1beta1
|
metadata:
|
||||||
id: mysql
|
labels:
|
||||||
# the port that this service should serve on
|
name: mysql
|
||||||
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:
|
|
||||||
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
|
||||||
|
|
|
@ -1,32 +1,31 @@
|
||||||
apiVersion: v1beta1
|
apiVersion: v1beta3
|
||||||
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
|
|
||||||
kind: Pod
|
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
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
apiVersion: v1beta3
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
name: mysql
|
|
||||||
name: mysql
|
|
||||||
spec:
|
|
||||||
ports:
|
|
||||||
- port: 3306
|
|
||||||
targetPort: 3306
|
|
||||||
selector:
|
|
||||||
name: mysql
|
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
apiVersion: v1beta3
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
name: wpfrontend
|
|
||||||
name: wpfrontend
|
|
||||||
spec:
|
|
||||||
ports:
|
|
||||||
- port: 80
|
|
||||||
targetPort: 80
|
|
||||||
selector:
|
|
||||||
name: wpfrontend
|
|
||||||
|
|
|
@ -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
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
|
apiVersion: v1beta3
|
||||||
kind: Service
|
kind: Service
|
||||||
apiVersion: v1beta1
|
metadata:
|
||||||
id: wpfrontend
|
labels:
|
||||||
# the port that this service should serve on
|
name: wpfrontend
|
||||||
port: 80
|
|
||||||
# identifies the set of pods to load balance
|
|
||||||
# traffic to.
|
|
||||||
selector:
|
|
||||||
name: wpfrontend
|
name: wpfrontend
|
||||||
# the container on each pod to connect to, can be a name
|
spec:
|
||||||
# (e.g. 'www') or a number (e.g. 80)
|
createExternalLoadBalancer: true
|
||||||
containerPort: 80
|
ports:
|
||||||
labels:
|
# the port that this service should serve on
|
||||||
name: wpfrontend
|
- port: 80
|
||||||
createExternalLoadBalancer: true
|
# label keys and values that must match in order to receive traffic for this service
|
||||||
|
selector:
|
||||||
|
name: wordpress
|
||||||
|
|
|
@ -1,31 +1,28 @@
|
||||||
apiVersion: v1beta1
|
apiVersion: v1beta3
|
||||||
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
|
|
||||||
kind: Pod
|
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
|
||||||
|
|
Loading…
Reference in New Issue