Kubernetes Course Labs

Hackathon Part 7 Solution

Remember you can scale down existing pods if you're low on resources:

kubectl scale deploy/products-api deploy/stock-api deploy/web sts/products-db --replicas 0

Deploy the Helm chart to a new namespace using a sample variables file:

helm install widg-uat -n widg-uat --create-namespace -f hackathon/files/helm/uat.yaml hackathon/solution-part-7/helm/widgetario

Check the objects:

kubectl get all -n widg-uat

kubectl get ingress -A

Add hosts for the new domains:

# On Windows (run as Admin)
./scripts/add-to-hosts.ps1 widgetario.uat 127.0.0.1
./scripts/add-to-hosts.ps1 api.widgetario.uat 127.0.0.1

# OR on Linux/macOS
./scripts/add-to-hosts.sh widgetario.uat 127.0.0.1
./scripts/add-to-hosts.sh api.widgetario.uat 127.0.0.1

Try the Products API:

curl -k https://api.widgetario.uat/products

Browse to http://widgetario.uat; you'll see a new Buy button from the latest image update

Deploy the build infrastructure:

kubectl apply -f hackathon/solution-part-7/infrastructure

When it's all running, push your local code to Gogs:

git remote add hackathon http://localhost:30031/kiamol/kiamol.git

git push hackathon main

create registry creds - add your details with variables or use the scripts in the Jenkins lab:

kubectl -n infra create secret docker-registry registry-creds --docker-server=$REGISTRY_SERVER --docker-username=$REGISTRY_USER --docker-password=$REGISTRY_PASSWORD

Create a configmap with the details for the image name - be sure to use a registry and domain you have push access for:

kubectl -n infra create configmap build-config --from-literal=REGISTRY=docker.io  --from-literal=REPOSITORY=$REGISTRY_USER 

Restart Jenkins to load the latest config:

kubectl rollout restart deploy/jenkins -n infra

Browse to Jenkins http://localhost:30007, sign in with the kiamol username and password

Open the Widgetario job in Jenkins, enable and build it. Confirm that your images build and are pushed with the correct tags.

Add the Helm deploy stage to Jenkins:

You can edit the Jenkisfile, or change the job to use the part 7 solution Jenkinsfile:

Build again and confirm the latest images are deployed in the new namespace.

Add smoke test domain to hosts file:

# On Windows (run as Admin)
./scripts/add-to-hosts.ps1 widgetario.smoke 127.0.0.1
./scripts/add-to-hosts.ps1 api.widgetario.smoke 127.0.0.1

# OR on Linux/macOS
./scripts/add-to-hosts.sh widgetario.smoke 127.0.0.1
./scripts/add-to-hosts.sh api.widgetario.smoke 127.0.0.1

Check the Products API:

curl -k https://api.widgetario.smoke/products

And test the app at http://widgetario.smoke