Solución Manage Kubernetes in Google Cloud: Challenge Lab

Published:

Estuve haciendo unos cursos de Google y quería compartir la solución de un Challenge Lab a modo de guía porque a veces cuesta encontrar las cosas, solo hay que modificar algunos valores que dejaré detallados y en negrita.

Curso en cuestión: Manage Kubernetes in Google Cloud: Challenge Lab.

Nota: a medida que avanzan es necesario ir chequeando el progreso, algunos tardan más que otros.

Task 1. Create a GKE cluster

En este punto debemos especificar el nombre del cluster y la versión, además ajustar la zona.

gcloud container clusters create hello-world-9bkj \
--cluster-version=1.27.3-gke.1700 \
--release-channel=regular \
--enable-autoscaling \
--num-nodes=3 \
--min-nodes=2 \
--max-nodes=6 \
--zone=us-central1-b
gcloud container clusters get-credentials hello-world-9bkj --zone=us-central1-b

Task 2. Enable Managed Prometheus on the GKE cluster

Cuidado con el namespace que pide hay que ajustarlo también, dejo todos los pasos.

gcloud container clusters update hello-world-9bkj --enable-managed-prometheus --zone us-central1-b

kubectl create ns gmp-ehyt

gsutil cp gs://spls/gsp510/prometheus-app.yaml .

sed -i 's+- image: <todo>+- image: nilebox/prometheus-example-app:latest+' prometheus-app.yaml

sed -i 's+- name: <todo>+- name: metrics+' prometheus-app.yaml

sed -i 's+name: <todo>+name: prometheus-test+' prometheus-app.yaml

kubectl apply -f prometheus-app.yaml -n gmp-ehyt

gsutil cp gs://spls/gsp510/pod-monitoring.yaml .

sed -i 's+name: <todo>+name: prometheus-test+' pod-monitoring.yaml

sed -i 's+app.kubernetes.io/name: <todo>+app.kubernetes.io/name: prometheus-test+' pod-monitoring.yaml

sed -i 's+app: <todo>+app: prometheus-test+' pod-monitoring.yaml

sed -i 's+interval: <todo>+interval: 30s+' pod-monitoring.yaml

kubectl apply -f pod-monitoring.yaml -n gmp-ehyt

Task 3. Deploy an application onto the GKE cluster

gsutil cp -r gs://spls/gsp510/hello-app/ .

kubectl apply -f ~/hello-app/manifests/helloweb-deployment.yaml -n gmp-ehyt

Task 4. Create a logs-based metric and alerting policy

Hay 2 partes, una es generar la query de logs y la policy.

Query in Logs Explorer

resource.type="k8s_pod"
severity=WARNING

Create metric with following detail

Metric type: Counter
Log Metric Name : pod-image-errors

Los valores nos lo dará Google.

Task 5. Update and re-deploy your app

cd ~/hello-app/manifests

sed -i 's+image: <todo>+image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0+' helloweb-deployment.yaml

kubectl delete deployment.apps/helloweb -n gmp-ehyt

kubectl apply -f helloweb-deployment.yaml -n gmp-ehyt

Task 6. Containerize your code and deploy it onto the cluster

cd ~/hello-app

sed -i 's+Version: 1.0.0+Version: 2.0.0+' main.go

gcloud auth configure-docker us-central1-docker.pkg.dev --quiet

Ajustar el project ID al que corresponda

gcloud builds submit -t us-central1-docker.pkg.dev/qwiklabs-gcp-01-115c88f9981f/sandbox-repo/hello-app:v2 .

kubectl set image deployment/helloweb -n gmp-ehyt hello-app=us-central1-docker.pkg.dev/qwiklabs-gcp-01-115c88f9981f/sandbox-repo/hello-app:v2

Hay que ajustar el nombre del service al que te toque

kubectl expose deployment helloweb -n gmp-ehyt --name=helloweb-service-up4q --type=LoadBalancer --port 8080 --target-port 8080
- Advertisement -
Jorge
Jorgehttps://nksistemas.com
Soy Jorge, Sr Sysadmin Linux/DevOps/SRE y creador de NKSistemas.com Trabajo con plataformas: Linux, Windows, AWS, GCP, VMware, Helm, kubernetes, Docker, etc.

Related articles