diff --git a/docs/tasks/run-application/deployment-patch-demo.yaml b/docs/tasks/run-application/deployment-patch-demo.yaml index f3f1bc34d85ac..b6b9528282447 100644 --- a/docs/tasks/run-application/deployment-patch-demo.yaml +++ b/docs/tasks/run-application/deployment-patch-demo.yaml @@ -3,6 +3,9 @@ kind: Deployment metadata: name: patch-demo spec: + selector: + matchLabels: + app: nginx replicas: 2 selector: matchLabels: diff --git a/docs/tasks/run-application/deployment-scale.yaml b/docs/tasks/run-application/deployment-scale.yaml index 01351c3b5ab8f..bd6c477b3f44b 100644 --- a/docs/tasks/run-application/deployment-scale.yaml +++ b/docs/tasks/run-application/deployment-scale.yaml @@ -1,8 +1,11 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1beta2 kind: Deployment metadata: name: nginx-deployment spec: + selector: + matchLabels: + app: nginx replicas: 4 # Update the replicas from 2 to 4 template: metadata: diff --git a/docs/tasks/run-application/deployment-update.yaml b/docs/tasks/run-application/deployment-update.yaml index 8f0ac0b48c682..7507e71109006 100644 --- a/docs/tasks/run-application/deployment-update.yaml +++ b/docs/tasks/run-application/deployment-update.yaml @@ -1,8 +1,11 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1beta2 kind: Deployment metadata: name: nginx-deployment spec: + selector: + matchLabels: + app: nginx replicas: 2 template: metadata: diff --git a/docs/tasks/run-application/deployment.yaml b/docs/tasks/run-application/deployment.yaml index 8d14e2ef08a82..06d622cce2f25 100644 --- a/docs/tasks/run-application/deployment.yaml +++ b/docs/tasks/run-application/deployment.yaml @@ -1,8 +1,11 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1beta2 kind: Deployment metadata: name: nginx-deployment spec: + selector: + matchLabels: + app: nginx replicas: 2 # tells deployment to run 2 pods matching the template template: # create pods using pod definition in this template metadata: diff --git a/docs/tasks/run-application/gce-volume.yaml b/docs/tasks/run-application/gce-volume.yaml deleted file mode 100644 index ddb9ecc3ce227..0000000000000 --- a/docs/tasks/run-application/gce-volume.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: v1 -kind: PersistentVolume -metadata: - name: mysql-pv -spec: - capacity: - storage: 20Gi - accessModes: - - ReadWriteOnce - gcePersistentDisk: - pdName: mysql-disk - fsType: ext4 diff --git a/docs/tasks/run-application/mysql-deployment.yaml b/docs/tasks/run-application/mysql-deployment.yaml index 1bf9671ef111e..f60e462817e1c 100644 --- a/docs/tasks/run-application/mysql-deployment.yaml +++ b/docs/tasks/run-application/mysql-deployment.yaml @@ -16,16 +16,18 @@ metadata: spec: accessModes: - ReadWriteOnce - storageClassName: "" resources: requests: storage: 20Gi --- -apiVersion: apps/v1beta1 +apiVersion: apps/v1beta2 kind: Deployment metadata: name: mysql spec: + selector: + matchLabels: + app: mysql strategy: type: Recreate template: diff --git a/docs/tasks/run-application/mysql-statefulset.yaml b/docs/tasks/run-application/mysql-statefulset.yaml index d8ee2d9ac95ae..6faddc3cb6b3e 100644 --- a/docs/tasks/run-application/mysql-statefulset.yaml +++ b/docs/tasks/run-application/mysql-statefulset.yaml @@ -1,62 +1,66 @@ -apiVersion: apps/v1beta1 +apiVersion: apps/v1beta2 kind: StatefulSet metadata: name: mysql spec: + selector: + matchLabels: + app: mysql serviceName: mysql replicas: 3 template: metadata: labels: 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: + 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: - name: mysql image: mysql:5.7 @@ -74,18 +78,20 @@ spec: mountPath: /etc/mysql/conf.d resources: requests: - cpu: 1 + cpu: 500m memory: 1Gi livenessProbe: exec: command: ["mysqladmin", "ping"] initialDelaySeconds: 30 + periodSeconds: 10 timeoutSeconds: 5 readinessProbe: exec: # Check we can execute queries over TCP (skip-networking is off). command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"] initialDelaySeconds: 5 + periodSeconds: 2 timeoutSeconds: 1 - name: xtrabackup image: gcr.io/google-samples/xtrabackup:1.0 @@ -154,11 +160,8 @@ spec: volumeClaimTemplates: - metadata: name: data - annotations: - volume.alpha.kubernetes.io/storage-class: default spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 10Gi - diff --git a/docs/tasks/run-application/patch-file.json b/docs/tasks/run-application/patch-file.json deleted file mode 100644 index bfa7488d4b064..0000000000000 --- a/docs/tasks/run-application/patch-file.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "spec": { - "template": { - "spec": { - "containers": [ - { - "name": "patch-demo-ctr-2", - "image": "redis" - } - ] - } - } - } -} diff --git a/docs/tasks/run-application/run-replicated-stateful-application.md b/docs/tasks/run-application/run-replicated-stateful-application.md index 9613bb2437d2d..5241d555b08db 100644 --- a/docs/tasks/run-application/run-replicated-stateful-application.md +++ b/docs/tasks/run-application/run-replicated-stateful-application.md @@ -1,6 +1,5 @@ --- approvers: -- bprashanth - enisoc - erictune - foxish @@ -225,7 +224,7 @@ by running a temporary container with the `mysql:5.7` image and running the `mysql` client binary. ```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 < - 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: - 1. Inspect the PersistentVolumeClaim: 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: ``` -kubectl run -it --rm --image=mysql:5.6 mysql-client -- mysql -h -p +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 @@ -220,14 +163,14 @@ Delete the deployed objects by name: ``` kubectl delete deployment,svc mysql kubectl delete pvc mysql-pv-claim -kubectl delete pv mysql-pv ``` -Also, if you are using Compute Engine disks: - -``` -gcloud compute disks delete mysql-disk -``` +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 +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 %} diff --git a/docs/tasks/run-application/run-stateless-application-deployment.md b/docs/tasks/run-application/run-stateless-application-deployment.md index f865d95c9ec0f..70802fb092a9d 100644 --- a/docs/tasks/run-application/run-stateless-application-deployment.md +++ b/docs/tasks/run-application/run-stateless-application-deployment.md @@ -38,7 +38,7 @@ a Deployment that runs the nginx:1.7.9 Docker image: 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: