diff --git a/chapter3/readme.adoc b/chapter3/readme.adoc index 5e8e84d..f576e46 100644 --- a/chapter3/readme.adoc +++ b/chapter3/readme.adoc @@ -192,6 +192,38 @@ If Helm has already been initialized on the cluster, then you may have to upgrad helm reset --force +== 3.9 Deploy Application to Kubernetes using Helm version 3 Charts + +**Code** + +. Install the Helm CLI: + + brew install kubernetes-helm ++ +If Helm CLI is already installed then use `brew upgrade kubernetes-helm`. ++ +. Check Helm version: + + helm version + +. Change to `manifests/charts` directory +. Install the Helm chart: + + helm install myapp ./myapp + +. Check that the resources are running: + + kubectl get svc,deployment,pods + +. Access the application: + + curl http://$(kubectl get svc/greeting \ + -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'):8080/hello + +. Delete the Helm chart: + + helm uninstall myapp + == 3.10 Debug Kubernetes Deployment using IntelliJ **Code** @@ -241,3 +273,51 @@ image::images/docker-debug3.png[] helm delete --purge myapp +== 3.10 Debug Kubernetes Deployment using IntelliJ with Helm version 3 + +**Code** + +You can debug a Kubernetes Pod if they're running on your machine. + +This was tested using Docker Desktop. + +. Install the Helm chart: + + helm install myapp myapp + +. Show service: ++ + $ kubectl get svc + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + greeting LoadBalancer 10.99.253.180 localhost 8080:30194/TCP,5005:31755/TCP 2m + kubernetes ClusterIP 10.96.0.1 443/TCP 123d ++ +Highlight the debug port is also forwarded. ++ +. In IntelliJ, `Run`, `Debug`, `Remote`: ++ +image::images/docker-debug1.png[] ++ +. Click on `Debug`, setup a breakpoint in the class: ++ +image::images/docker-debug2.png[] ++ +Wait for about 10 seconds. ++ +. Access the application: + + curl http://$(kubectl get svc/greeting \ + -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'):8080/hello + +. Show the breakpoint hit in IntelliJ: ++ +image::images/docker-debug3.png[] ++ +. Click on green button to continue execution +. Invoke the application: + + curl http://locahost:8080/hello + +. Delete the Helm chart: + + helm uninstall myapp diff --git a/chapter4/readme.adoc b/chapter4/readme.adoc index ef17594..94c0a61 100644 --- a/chapter4/readme.adoc +++ b/chapter4/readme.adoc @@ -132,3 +132,47 @@ It shows the port `8080` and `5005` are published and an Elastic Load Balancer i helm delete --purge myapp +== 4.3 Migrate Application to Kubernetes Cluster on AWS with Helm version 3 + +**Code** + +. Explicitly set the context: + + kubectl config use-context arun@k8s-course.us-west-2.eksctl.io + +. Check the list of pods: + + kubectl get pods -n kube-system + NAME READY STATUS RESTARTS AGE + aws-node-6h4r9 1/1 Running 1 16m + aws-node-7rwkw 1/1 Running 1 16m + aws-node-k9g6s 1/1 Running 0 16m + aws-node-t6k6v 1/1 Running 1 16m + kube-dns-64b69465b4-vpxjq 3/3 Running 0 23m + kube-proxy-bnkj6 1/1 Running 0 16m + kube-proxy-bqths 1/1 Running 0 16m + kube-proxy-m7ctf 1/1 Running 0 16m + kube-proxy-tszj5 1/1 Running 0 16m + tiller-deploy-895d57dd9-zt2s2 1/1 Running 0 7s + +. Redeploy the application: + + helm install myapp manifests/charts/myapp + +. Get the service: ++ + kubectl get svc + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + greeting LoadBalancer 10.100.110.146 a798a47cd104211e986290adde103247-521253658.us-west-2.elb.amazonaws.com 8080:31627/TCP,5005:30216/TCP 2m + kubernetes ClusterIP 10.100.0.1 443/TCP 18h ++ +It shows the port `8080` and `5005` are published and an Elastic Load Balancer is provisioned. It takes about three minutes for the load balancer to be ready. ++ +. Access the application: + + curl http://$(kubectl get svc/greeting \ + -o jsonpath='{.status.loadBalancer.ingress[0].hostname}'):8080/hello + +. Delete the application: + + helm uninstall myapp diff --git a/chapter5/readme.adoc b/chapter5/readme.adoc index 63954f1..505f560 100644 --- a/chapter5/readme.adoc +++ b/chapter5/readme.adoc @@ -32,6 +32,14 @@ More details at https://aws.amazon.com/blogs/opensource/getting-started-istio-ek --namespace istio-system \ install/kubernetes/helm/istio +. With Helm v3: + + helm install \ + istio \ + install/kubernetes/helm/istio \ + --wait \ + --namespace istio-system + . Verify the list of pods: kubectl get pods -n istio-system @@ -63,6 +71,10 @@ More details at https://aws.amazon.com/blogs/opensource/getting-started-istio-ek helm delete myapp --purge helm install --name myapp myapp-hello-howdy + + #helm v3 + helm uninstall myapp + helm install myapp myapp-hello-howdy + Note, there is no `type: LoadBalancer` in this case. The service will be exposed using Istio Ingress gateway so that Istio can do the traffic split. + @@ -191,5 +203,7 @@ image::images/kiali-apps.png[] . Remove Istio helm delete istio --purge + #helm v3 + helm uninstall istio kubectl delete -f install/kubernetes/helm/istio/templates/crds.yaml -n istio-system diff --git a/chapter6/readme.adoc b/chapter6/readme.adoc index 0ca6bfd..e6e9123 100644 --- a/chapter6/readme.adoc +++ b/chapter6/readme.adoc @@ -38,6 +38,9 @@ https://github.com/GoogleContainerTools/skaffold[Skaffold] is a command line uti helm delete myapp --purge + #helm v3 + helm uninstall myapp + . Download Skaffold: brew install skaffold @@ -52,6 +55,10 @@ https://github.com/GoogleContainerTools/skaffold[Skaffold] is a command line uti . Refresh the page in browser to see the output. +. Remove the Skaffold resources from the application directory: + + skaffold delete + Same Java application, now continuously built through Skaffold and deployed to a local Kubernetes cluster. This can also be integrated with Jib. This can also be deployed to a remote Kubernetes cluster. === 6.2 AWS CodePipeline diff --git a/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-hello.yaml b/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-hello.yaml index 2788f57..b7054a2 100644 --- a/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-hello.yaml +++ b/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-hello.yaml @@ -1,4 +1,4 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: greeting-hello @@ -7,6 +7,9 @@ metadata: {{- template "labels" . }} spec: replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: greeting template: metadata: labels: diff --git a/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-howdy.yaml b/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-howdy.yaml index 1d7cf92..3489fe8 100644 --- a/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-howdy.yaml +++ b/manifests/charts/myapp-hello-howdy/templates/greeting-deployment-howdy.yaml @@ -1,4 +1,4 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: greeting-howdy @@ -7,6 +7,9 @@ metadata: {{- template "labels" . }} spec: replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: greeting template: metadata: labels: diff --git a/manifests/charts/myapp/templates/greeting-deployment.yaml b/manifests/charts/myapp/templates/greeting-deployment.yaml index bd458ce..7205f6b 100644 --- a/manifests/charts/myapp/templates/greeting-deployment.yaml +++ b/manifests/charts/myapp/templates/greeting-deployment.yaml @@ -1,19 +1,22 @@ -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: - name: greeting + name: {{ .Chart.Name }} labels: - name: greeting + name: {{ .Chart.Name }} {{- template "labels" . }} spec: replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app: {{ .Chart.Name }} template: metadata: labels: - app: greeting + app: {{ .Chart.Name }} spec: containers: - - name: greeting + - name: {{ .Chart.Name }} image: {{ .Values.greeting.image }}:{{ .Values.image.tag }} imagePullPolicy: {{ .Values.image.pullPolicy }} ports: diff --git a/manifests/charts/myapp/templates/greeting-service.yaml b/manifests/charts/myapp/templates/greeting-service.yaml index 4e3f158..08a4b53 100644 --- a/manifests/charts/myapp/templates/greeting-service.yaml +++ b/manifests/charts/myapp/templates/greeting-service.yaml @@ -1,13 +1,13 @@ apiVersion: v1 kind: Service metadata: - name: greeting + name: {{ .Chart.Name }} labels: - name: greeting + name: {{ .Chart.Name }} {{- template "labels" . }} spec: selector: - app: greeting + app: {{ .Chart.Name }} ports: - name: http protocol: TCP