Skip to content

nogibjj/coursera-applied-de-kubernetes-lab

Repository files navigation

Kubernetes examples

Lab Minikube (based on official tutorial on https://kubernetes.io)

  1. Launch GitHub Codespace
  2. Run minikube start to start cluster
  3. Run minikube dashboard --url to view dashboard in a new terminal
  4. Hover over link and "follow link"
  5. Create a deployment: kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.39 -- /agnhost netexec --http-port=8080
  6. View deployment: kubectl get deployments
  7. View pods: kubectl get pods
  8. Create service and expose it: kubectl expose deployment hello-node --type=LoadBalancer --port=8080
  9. View services: kubectl get services
  10. Curl the url shown, for example: curl http://192.168.49.2:31839 or change to your URL.
  11. Cleanup
kubectl delete service hello-node
kubectl delete deployment hello-node
minikube stop

Task 2: Deploy with Kubernetes FastAPI app

  1. Push container to DockerHub (Optional): i.e. docker build -t <hub-user>/<repo-name>[:<tag>] and docker push <hub-user>/<repo-name>:<tag> Example of a pushed FastAPI container here: https://hub.docker.com/repository/docker/noahgift/fastapi-kube
  2. minikube start
  3. minikube dashboard --url
  4. Hover over link and "follow link"
  5. Create a deployment: kubectl create deployment hello-fastapi --image=registry.hub.docker.com/noahgift/fastapi-kube
  6. View deployment: kubectl get deployments
  7. Create service and expose it: kubectl expose deployment hello-fastapi --type=LoadBalancer --port=8080
  8. View services: kubectl get service hello-fastapi
  9. minikube service hello-fastapi --url
  10. Curl web service: i.e. curl http://192.168.49.2:31224
  11. Cleanup
  12. Cleanup
kubectl delete service hello-fastapi
kubectl delete deployment hello-fastapi
minikube stop

Notes below

fastapi-from-zero

A repository to demonstrate FastAPI

/docs get to swagger

fastapi

Docker

docker build . docker image ls #find image docker run -p 127.0.0.1:8080:8080 93fa55efa692

Cloud9 + ECR + App Runner

continuous-delivery

  • Clone repo into Cloud9 (pick a machine with decent size CPU and RAM if possible, but students should use micro)
  • Add ssh keys to GitHub
  • resize to bigger disk
  • Create virtualenv and add to bashrc and source python3 -m venv ~/.venv && echo 'source ~/.venv/bin/activate' >> ~/.bashrc && source ~/.bashrc
  • cd into checkout and run make install
  • Preview running FastAPI app after running: python main.py

Screen Shot 2022-09-28 at 12 32 52 PM

  • Create ECR repository by right-click in Cloud9

Screen Shot 2022-09-28 at 12 34 44 PM

  • Navigate to ECR repo created or whatever you named it and follow "push" instructions

    Screen Shot 2022-09-28 at 12 36 45 PM
  • Navigate to AWS App Runner and Setup Continuous Delivery using ECR

    Screen Shot 2022-09-28 at 12 41 21 PM
  • Setup AWS Code Build to push container after each build (which triggers auto-deploy)

    Screen Shot 2022-09-28 at 12 50 19 PM

See following buildspec.yml and Makefile

References

About

Labs for Coursera Applied Kubernetes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published