[1.8] Update "Run Applications" tasks to apps/v1beta2. (#5525)
* Update replicated stateful application task for 1.8. * Update single instance stateful app task for 1.8. * Update stateless app task for 1.8. * Update kubectl patch task for 1.8.
This commit is contained in:
@@ -3,6 +3,9 @@ kind: Deployment
|
|||||||
metadata:
|
metadata:
|
||||||
name: patch-demo
|
name: patch-demo
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx
|
||||||
replicas: 2
|
replicas: 2
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-deployment
|
name: nginx-deployment
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx
|
||||||
replicas: 4 # Update the replicas from 2 to 4
|
replicas: 4 # Update the replicas from 2 to 4
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-deployment
|
name: nginx-deployment
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx
|
||||||
replicas: 2
|
replicas: 2
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: nginx-deployment
|
name: nginx-deployment
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: nginx
|
||||||
replicas: 2 # tells deployment to run 2 pods matching the template
|
replicas: 2 # tells deployment to run 2 pods matching the template
|
||||||
template: # create pods using pod definition in this template
|
template: # create pods using pod definition in this template
|
||||||
metadata:
|
metadata:
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: PersistentVolume
|
|
||||||
metadata:
|
|
||||||
name: mysql-pv
|
|
||||||
spec:
|
|
||||||
capacity:
|
|
||||||
storage: 20Gi
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
gcePersistentDisk:
|
|
||||||
pdName: mysql-disk
|
|
||||||
fsType: ext4
|
|
||||||
@@ -16,16 +16,18 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
accessModes:
|
accessModes:
|
||||||
- ReadWriteOnce
|
- ReadWriteOnce
|
||||||
storageClassName: ""
|
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 20Gi
|
storage: 20Gi
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta2
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
name: mysql
|
name: mysql
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mysql
|
||||||
strategy:
|
strategy:
|
||||||
type: Recreate
|
type: Recreate
|
||||||
template:
|
template:
|
||||||
|
|||||||
@@ -1,62 +1,66 @@
|
|||||||
apiVersion: apps/v1beta1
|
apiVersion: apps/v1beta2
|
||||||
kind: StatefulSet
|
kind: StatefulSet
|
||||||
metadata:
|
metadata:
|
||||||
name: mysql
|
name: mysql
|
||||||
spec:
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mysql
|
||||||
serviceName: mysql
|
serviceName: mysql
|
||||||
replicas: 3
|
replicas: 3
|
||||||
template:
|
template:
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: mysql
|
app: mysql
|
||||||
annotations:
|
|
||||||
pod.beta.kubernetes.io/init-containers: '[
|
|
||||||
{
|
|
||||||
"name": "init-mysql",
|
|
||||||
"image": "mysql:5.7",
|
|
||||||
"command": ["bash", "-c", "
|
|
||||||
set -ex\n
|
|
||||||
# Generate mysql server-id from pod ordinal index.\n
|
|
||||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1\n
|
|
||||||
ordinal=${BASH_REMATCH[1]}\n
|
|
||||||
echo [mysqld] > /mnt/conf.d/server-id.cnf\n
|
|
||||||
# Add an offset to avoid reserved server-id=0 value.\n
|
|
||||||
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf\n
|
|
||||||
# Copy appropriate conf.d files from config-map to emptyDir.\n
|
|
||||||
if [[ $ordinal -eq 0 ]]; then\n
|
|
||||||
cp /mnt/config-map/master.cnf /mnt/conf.d/\n
|
|
||||||
else\n
|
|
||||||
cp /mnt/config-map/slave.cnf /mnt/conf.d/\n
|
|
||||||
fi\n
|
|
||||||
"],
|
|
||||||
"volumeMounts": [
|
|
||||||
{"name": "conf", "mountPath": "/mnt/conf.d"},
|
|
||||||
{"name": "config-map", "mountPath": "/mnt/config-map"}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "clone-mysql",
|
|
||||||
"image": "gcr.io/google-samples/xtrabackup:1.0",
|
|
||||||
"command": ["bash", "-c", "
|
|
||||||
set -ex\n
|
|
||||||
# Skip the clone if data already exists.\n
|
|
||||||
[[ -d /var/lib/mysql/mysql ]] && exit 0\n
|
|
||||||
# Skip the clone on master (ordinal index 0).\n
|
|
||||||
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1\n
|
|
||||||
ordinal=${BASH_REMATCH[1]}\n
|
|
||||||
[[ $ordinal -eq 0 ]] && exit 0\n
|
|
||||||
# Clone data from previous peer.\n
|
|
||||||
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql\n
|
|
||||||
# Prepare the backup.\n
|
|
||||||
xtrabackup --prepare --target-dir=/var/lib/mysql\n
|
|
||||||
"],
|
|
||||||
"volumeMounts": [
|
|
||||||
{"name": "data", "mountPath": "/var/lib/mysql", "subPath": "mysql"},
|
|
||||||
{"name": "conf", "mountPath": "/etc/mysql/conf.d"}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]'
|
|
||||||
spec:
|
spec:
|
||||||
|
initContainers:
|
||||||
|
- name: init-mysql
|
||||||
|
image: mysql:5.7
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- "-c"
|
||||||
|
- |
|
||||||
|
set -ex
|
||||||
|
# Generate mysql server-id from pod ordinal index.
|
||||||
|
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
||||||
|
ordinal=${BASH_REMATCH[1]}
|
||||||
|
echo [mysqld] > /mnt/conf.d/server-id.cnf
|
||||||
|
# Add an offset to avoid reserved server-id=0 value.
|
||||||
|
echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf
|
||||||
|
# Copy appropriate conf.d files from config-map to emptyDir.
|
||||||
|
if [[ $ordinal -eq 0 ]]; then
|
||||||
|
cp /mnt/config-map/master.cnf /mnt/conf.d/
|
||||||
|
else
|
||||||
|
cp /mnt/config-map/slave.cnf /mnt/conf.d/
|
||||||
|
fi
|
||||||
|
volumeMounts:
|
||||||
|
- name: conf
|
||||||
|
mountPath: /mnt/conf.d
|
||||||
|
- name: config-map
|
||||||
|
mountPath: /mnt/config-map
|
||||||
|
- name: clone-mysql
|
||||||
|
image: gcr.io/google-samples/xtrabackup:1.0
|
||||||
|
command:
|
||||||
|
- bash
|
||||||
|
- "-c"
|
||||||
|
- |
|
||||||
|
set -ex
|
||||||
|
# Skip the clone if data already exists.
|
||||||
|
[[ -d /var/lib/mysql/mysql ]] && exit 0
|
||||||
|
# Skip the clone on master (ordinal index 0).
|
||||||
|
[[ `hostname` =~ -([0-9]+)$ ]] || exit 1
|
||||||
|
ordinal=${BASH_REMATCH[1]}
|
||||||
|
[[ $ordinal -eq 0 ]] && exit 0
|
||||||
|
# Clone data from previous peer.
|
||||||
|
ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql
|
||||||
|
# Prepare the backup.
|
||||||
|
xtrabackup --prepare --target-dir=/var/lib/mysql
|
||||||
|
volumeMounts:
|
||||||
|
- name: data
|
||||||
|
mountPath: /var/lib/mysql
|
||||||
|
subPath: mysql
|
||||||
|
- name: conf
|
||||||
|
mountPath: /etc/mysql/conf.d
|
||||||
containers:
|
containers:
|
||||||
- name: mysql
|
- name: mysql
|
||||||
image: mysql:5.7
|
image: mysql:5.7
|
||||||
@@ -74,18 +78,20 @@ spec:
|
|||||||
mountPath: /etc/mysql/conf.d
|
mountPath: /etc/mysql/conf.d
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: 1
|
cpu: 500m
|
||||||
memory: 1Gi
|
memory: 1Gi
|
||||||
livenessProbe:
|
livenessProbe:
|
||||||
exec:
|
exec:
|
||||||
command: ["mysqladmin", "ping"]
|
command: ["mysqladmin", "ping"]
|
||||||
initialDelaySeconds: 30
|
initialDelaySeconds: 30
|
||||||
|
periodSeconds: 10
|
||||||
timeoutSeconds: 5
|
timeoutSeconds: 5
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
exec:
|
exec:
|
||||||
# Check we can execute queries over TCP (skip-networking is off).
|
# Check we can execute queries over TCP (skip-networking is off).
|
||||||
command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
|
command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
|
||||||
initialDelaySeconds: 5
|
initialDelaySeconds: 5
|
||||||
|
periodSeconds: 2
|
||||||
timeoutSeconds: 1
|
timeoutSeconds: 1
|
||||||
- name: xtrabackup
|
- name: xtrabackup
|
||||||
image: gcr.io/google-samples/xtrabackup:1.0
|
image: gcr.io/google-samples/xtrabackup:1.0
|
||||||
@@ -154,11 +160,8 @@ spec:
|
|||||||
volumeClaimTemplates:
|
volumeClaimTemplates:
|
||||||
- metadata:
|
- metadata:
|
||||||
name: data
|
name: data
|
||||||
annotations:
|
|
||||||
volume.alpha.kubernetes.io/storage-class: default
|
|
||||||
spec:
|
spec:
|
||||||
accessModes: ["ReadWriteOnce"]
|
accessModes: ["ReadWriteOnce"]
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
storage: 10Gi
|
storage: 10Gi
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"spec": {
|
|
||||||
"template": {
|
|
||||||
"spec": {
|
|
||||||
"containers": [
|
|
||||||
{
|
|
||||||
"name": "patch-demo-ctr-2",
|
|
||||||
"image": "redis"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
approvers:
|
approvers:
|
||||||
- bprashanth
|
|
||||||
- enisoc
|
- enisoc
|
||||||
- erictune
|
- erictune
|
||||||
- foxish
|
- foxish
|
||||||
@@ -225,7 +224,7 @@ by running a temporary container with the `mysql:5.7` image and running the
|
|||||||
`mysql` client binary.
|
`mysql` client binary.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl run mysql-client --image=mysql:5.7 -i -t --rm --restart=Never --\
|
kubectl run mysql-client --image=mysql:5.7 -i --rm --restart=Never --\
|
||||||
mysql -h mysql-0.mysql <<EOF
|
mysql -h mysql-0.mysql <<EOF
|
||||||
CREATE DATABASE test;
|
CREATE DATABASE test;
|
||||||
CREATE TABLE test.messages (message VARCHAR(250));
|
CREATE TABLE test.messages (message VARCHAR(250));
|
||||||
|
|||||||
@@ -24,48 +24,13 @@ application is MySQL.
|
|||||||
|
|
||||||
* {% include task-tutorial-prereqs.md %}
|
* {% include task-tutorial-prereqs.md %}
|
||||||
|
|
||||||
* For data persistence we will create a Persistent Volume that
|
* {% include default-storage-class-prereqs.md %}
|
||||||
references a disk in your
|
|
||||||
environment. See
|
|
||||||
[here](/docs/user-guide/persistent-volumes/#types-of-persistent-volumes) for
|
|
||||||
the types of environments supported. This Tutorial will demonstrate
|
|
||||||
`GCEPersistentDisk` but any type will work. `GCEPersistentDisk`
|
|
||||||
volumes only work on Google Compute Engine.
|
|
||||||
|
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
|
|
||||||
|
|
||||||
{% capture lessoncontent %}
|
{% capture lessoncontent %}
|
||||||
|
|
||||||
## Set up a disk in your environment
|
|
||||||
|
|
||||||
You can use any type of persistent volume for your stateful app. See
|
|
||||||
[Types of Persistent Volumes](/docs/user-guide/persistent-volumes/#types-of-persistent-volumes)
|
|
||||||
for a list of supported environment disks. For Google Compute Engine, run:
|
|
||||||
|
|
||||||
```
|
|
||||||
gcloud compute disks create --size=20GB mysql-disk
|
|
||||||
```
|
|
||||||
|
|
||||||
Next create a PersistentVolume that points to the `mysql-disk`
|
|
||||||
disk just created. Here is a configuration file for a PersistentVolume
|
|
||||||
that points to the Compute Engine disk above:
|
|
||||||
|
|
||||||
{% include code.html language="yaml" file="gce-volume.yaml" ghlink="/docs/tasks/run-application/gce-volume.yaml" %}
|
|
||||||
|
|
||||||
Notice that the `pdName: mysql-disk` line matches the name of the disk
|
|
||||||
in the Compute Engine environment. See the
|
|
||||||
[Persistent Volumes](/docs/concepts/storage/persistent-volumes/)
|
|
||||||
for details on writing a PersistentVolume configuration file for other
|
|
||||||
environments.
|
|
||||||
|
|
||||||
Create the persistent volume:
|
|
||||||
|
|
||||||
```
|
|
||||||
kubectl create -f https://k8s.io/docs/tasks/run-application/gce-volume.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Deploy MySQL
|
## Deploy MySQL
|
||||||
|
|
||||||
You can run a stateful application by creating a Kubernetes Deployment
|
You can run a stateful application by creating a Kubernetes Deployment
|
||||||
@@ -74,8 +39,8 @@ PersistentVolumeClaim. For example, this YAML file describes a
|
|||||||
Deployment that runs MySQL and references the PersistentVolumeClaim. The file
|
Deployment that runs MySQL and references the PersistentVolumeClaim. The file
|
||||||
defines a volume mount for /var/lib/mysql, and then creates a
|
defines a volume mount for /var/lib/mysql, and then creates a
|
||||||
PersistentVolumeClaim that looks for a 20G volume. This claim is
|
PersistentVolumeClaim that looks for a 20G volume. This claim is
|
||||||
satisfied by any volume that meets the requirements, in this case, the
|
satisfied by any existing volume that meets the requirements,
|
||||||
volume created above.
|
or by a dynamic provisioner.
|
||||||
|
|
||||||
Note: The password is defined in the config yaml, and this is insecure. See
|
Note: The password is defined in the config yaml, and this is insecure. See
|
||||||
[Kubernetes Secrets](/docs/concepts/configuration/secret/)
|
[Kubernetes Secrets](/docs/concepts/configuration/secret/)
|
||||||
@@ -134,28 +99,6 @@ for a secure solution.
|
|||||||
NAME READY STATUS RESTARTS AGE
|
NAME READY STATUS RESTARTS AGE
|
||||||
mysql-63082529-2z3ki 1/1 Running 0 3m
|
mysql-63082529-2z3ki 1/1 Running 0 3m
|
||||||
|
|
||||||
1. Inspect the Persistent Volume:
|
|
||||||
|
|
||||||
kubectl describe pv mysql-pv
|
|
||||||
|
|
||||||
Name: mysql-pv
|
|
||||||
Labels: <none>
|
|
||||||
Annotations: pv.kubernetes.io/bound-by-controller=yes
|
|
||||||
StorageClass:
|
|
||||||
Status: Bound
|
|
||||||
Claim: default/mysql-pv-claim
|
|
||||||
Reclaim Policy: Retain
|
|
||||||
Access Modes: RWO
|
|
||||||
Capacity: 20Gi
|
|
||||||
Message:
|
|
||||||
Source:
|
|
||||||
Type: GCEPersistentDisk (a Persistent Disk resource in Google Compute Engine)
|
|
||||||
PDName: mysql-disk
|
|
||||||
FSType: ext4
|
|
||||||
Partition: 0
|
|
||||||
ReadOnly: false
|
|
||||||
Events: <none>
|
|
||||||
|
|
||||||
1. Inspect the PersistentVolumeClaim:
|
1. Inspect the PersistentVolumeClaim:
|
||||||
|
|
||||||
kubectl describe pvc mysql-pv-claim
|
kubectl describe pvc mysql-pv-claim
|
||||||
@@ -183,7 +126,7 @@ behind a Service and you don't intend to increase the number of Pods.
|
|||||||
Run a MySQL client to connect to the server:
|
Run a MySQL client to connect to the server:
|
||||||
|
|
||||||
```
|
```
|
||||||
kubectl run -it --rm --image=mysql:5.6 mysql-client -- mysql -h <pod-ip> -p <password>
|
kubectl run -it --rm --image=mysql:5.6 --restart=Never mysql-client -- mysql -h mysql -ppassword
|
||||||
```
|
```
|
||||||
|
|
||||||
This command creates a new Pod in the cluster running a MySQL client
|
This command creates a new Pod in the cluster running a MySQL client
|
||||||
@@ -220,14 +163,14 @@ Delete the deployed objects by name:
|
|||||||
```
|
```
|
||||||
kubectl delete deployment,svc mysql
|
kubectl delete deployment,svc mysql
|
||||||
kubectl delete pvc mysql-pv-claim
|
kubectl delete pvc mysql-pv-claim
|
||||||
kubectl delete pv mysql-pv
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Also, if you are using Compute Engine disks:
|
If you manually provisioned a PersistentVolume, you also need to manually
|
||||||
|
delete it, as well as release the underlying resource.
|
||||||
```
|
If you used a dynamic provisioner, it automatically deletes the
|
||||||
gcloud compute disks delete mysql-disk
|
PersistentVolume when it sees that you deleted the PersistentVolumeClaim.
|
||||||
```
|
Some dynamic provisioners (such as those for EBS and PD) also release the
|
||||||
|
underlying resource upon deleting the PersistentVolume.
|
||||||
|
|
||||||
{% endcapture %}
|
{% endcapture %}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ a Deployment that runs the nginx:1.7.9 Docker image:
|
|||||||
|
|
||||||
1. Create a Deployment based on the YAML file:
|
1. Create a Deployment based on the YAML file:
|
||||||
|
|
||||||
kubectl create -f https://k8s.io/docs/tasks/run-application/deployment.yaml
|
kubectl apply -f https://k8s.io/docs/tasks/run-application/deployment.yaml
|
||||||
|
|
||||||
1. Display information about the Deployment:
|
1. Display information about the Deployment:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user