From b04ee9e5b404a59a47a9187849ecbd774b44b46a Mon Sep 17 00:00:00 2001 From: Saurabh Saxena Date: Fri, 16 Oct 2020 23:20:01 +0530 Subject: [PATCH 1/2] Fix K8s Deployment manifests. 1. Remove extensions/v1beta1 from apiVersion 2. Added spec.selector --- kubernetes/deployments/auth.yaml | 6 +++++- kubernetes/deployments/frontend.yaml | 6 +++++- kubernetes/deployments/hello-canary.yaml | 7 ++++++- kubernetes/deployments/hello-green.yaml | 7 ++++++- kubernetes/deployments/hello.yaml | 7 ++++++- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/kubernetes/deployments/auth.yaml b/kubernetes/deployments/auth.yaml index 0b83cec..364996c 100644 --- a/kubernetes/deployments/auth.yaml +++ b/kubernetes/deployments/auth.yaml @@ -1,9 +1,13 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: auth spec: replicas: 1 + selector: + matchLabels: + app: auth + track: stable template: metadata: labels: diff --git a/kubernetes/deployments/frontend.yaml b/kubernetes/deployments/frontend.yaml index c319306..916a549 100644 --- a/kubernetes/deployments/frontend.yaml +++ b/kubernetes/deployments/frontend.yaml @@ -1,9 +1,13 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: frontend spec: replicas: 1 + selector: + matchLabels: + app: frontend + track: stable template: metadata: labels: diff --git a/kubernetes/deployments/hello-canary.yaml b/kubernetes/deployments/hello-canary.yaml index ef4190e..95b2602 100644 --- a/kubernetes/deployments/hello-canary.yaml +++ b/kubernetes/deployments/hello-canary.yaml @@ -1,9 +1,14 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: hello-canary spec: replicas: 1 + selector: + matchLabels: + app: hello + track: canary + version: 2.0.0 template: metadata: labels: diff --git a/kubernetes/deployments/hello-green.yaml b/kubernetes/deployments/hello-green.yaml index 8c47471..3f1ac80 100644 --- a/kubernetes/deployments/hello-green.yaml +++ b/kubernetes/deployments/hello-green.yaml @@ -1,9 +1,14 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: hello-green spec: replicas: 3 + selector: + matchLabels: + app: hello + track: stable + version: 2.0.0 template: metadata: labels: diff --git a/kubernetes/deployments/hello.yaml b/kubernetes/deployments/hello.yaml index e3315a1..bc8dcd8 100644 --- a/kubernetes/deployments/hello.yaml +++ b/kubernetes/deployments/hello.yaml @@ -1,9 +1,14 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: hello spec: replicas: 3 + selector: + matchLabels: + app: hello + track: stable + version: 1.0.0 template: metadata: labels: From be6191e15f9da2f1320f7242906af5657a551d96 Mon Sep 17 00:00:00 2001 From: Saurabh Saxena Date: Fri, 16 Oct 2020 23:39:10 +0530 Subject: [PATCH 2/2] Update Labs document 1. Update create deployment commands to use "apply" and "--record" for history versioning. 2. Update Configure kubectl document for alias and autocomplete. --- labs/creating-and-managing-deployments.md | 8 ++++---- labs/install-and-configure-kubectl.md | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/labs/creating-and-managing-deployments.md b/labs/creating-and-managing-deployments.md index 268167d..eff994b 100644 --- a/labs/creating-and-managing-deployments.md +++ b/labs/creating-and-managing-deployments.md @@ -17,7 +17,7 @@ You will also define internal services for the `auth` and `hello` deployments an ### Create and Expose the Auth Deployment ``` -kubectl create -f deployments/auth.yaml +kubectl apply -f deployments/auth.yaml --record ``` ``` @@ -31,7 +31,7 @@ kubectl create -f services/auth.yaml ### Create and Expose the Hello Deployment ``` -kubectl create -f deployments/hello.yaml +kubectl apply -f deployments/hello.yaml --record ``` ``` @@ -50,7 +50,7 @@ kubectl create configmap nginx-frontend-conf --from-file=nginx/frontend.conf ``` ``` -kubectl create -f deployments/frontend.yaml +kubectl apply -f deployments/frontend.yaml --record ``` ``` @@ -111,4 +111,4 @@ curl -k https:// ## Summary -Deployments are the preferred way to manage application deployments. You learned how to create, expose and scale deployments. \ No newline at end of file +Deployments are the preferred way to manage application deployments. You learned how to create, expose and scale deployments. diff --git a/labs/install-and-configure-kubectl.md b/labs/install-and-configure-kubectl.md index b0b7054..e232ec9 100644 --- a/labs/install-and-configure-kubectl.md +++ b/labs/install-and-configure-kubectl.md @@ -22,6 +22,24 @@ sudo cp kubectl /usr/local/bin/kubectl ### Configure kubectl +Configure alias and autocomplete Bash: +```.bash +echo "alias k=kubectl" >> ~/.bashrc +echo "source <(kubectl completion bash)" >> ~/.bashrc +echo "complete -F __start_kubectl k" >> ~/.bashrc + +source ~/.bashrc +``` + +Configure alias and autocomplete Zsh: +```.zsh +echo "alias k=kubectl" >> ~/.zshrc +echo "[[ $commands[kubectl] ]] && source <(kubectl completion zsh)" >> ~/.zshrc +echo "complete -F __start_kubectl k" >> ~/.zshrc + +source ~/.zshrc +``` + Download the client credentials and CA cert: ```