Repository for the K8s in 1 hour video (https://www.youtube.com/watch?v=s_o8dwzRlu4)
This is an example Kubernetes project that creates a simple example Node app with MongoDB, and configures the server environment with .env vars for the Node app, and configures the Mongo db with an initial user.
The project will look like this:
The basics of Kubernetes: https://www.doabledanny.com/kubernetes-basics
("K8" is shorthand for Kubernetes. It refers to the eight letters between the "K" and "s" in Kubernetes (Kubernetes))
- mongo-config.yaml
- mongo-secret.yaml
- mongo.yaml
- webapp.yaml
minikube start (ensure you've opened up Docker Desktop first)
minikube status
minikube ip
kubectl get node
kubectl get pod (see pods)
kubectl get svc
kubectl get all (see all components in the cluster -- but it doesn't show configMap and Secret, so:)
kubectl get configmap
kubectl get secret
Apply command manages applications through files containing K8s resources. -f stands for file. Whatever is defined in the file is created, e.g. ConfigMap, Service, Deployment etc.:
kubectl apply -f mongo-congig.yaml
kubectl apply -f mongo-secret.yaml
kubectl apply -f mongo.yaml
kubectl apply -f webapp.yaml
Notice that we created mongo config and secret first, because the mongo db depends on it, and we create the mongo db before the webapp, because the webapp depends on it.
kubectl get pod -o wide
kubectl get node -o wide (can also get the cluster ip with this as well as `minkube ip`)
kubectl describe svc {svc-name}
kubectl describe pod {pod-name}
kubectl logs {pod-name}
e.g. kubectl logs webapp-deployment-7f479b7c79-v828v
=> "app listening on port 3000!"
You can also stream the logs with -f option:
kubectl logs webapp-deployment-7f479b7c79-v828v -f
- Find what public ip the cluster is available on with
kubectl get node -o wide
=> INTERNAL-IP orminikube up
. - Find the NodePort number: look inside your webapp's service config for nodePort, or
kubectl get svc
- Access MinikubeIP:NodePort in the browser, e.g. http://192.168.49.2:30100/
Or, if that doesn't work:
minikube stop
⚠️ Known issue - Minikube IP not accessible
If you can't access the NodePort service webapp with MinikubeIP:NodePort
, execute the following command:
minikube service webapp-service
Delete all: kubectl delete all --all
Delete configmap: kubectl delete configmap configmap-name
Delete secret: kubectl delete secret secret-name
Delete service: kubectl delete svc service-name
- mongodb image on Docker Hub: https://hub.docker.com/_/mongo
- webapp image on Docker Hub: https://hub.docker.com/repository/docker/nanajanashia/k8s-demo-app
- k8s official documentation: https://kubernetes.io/docs/home/
- webapp code repo: https://gitlab.com/nanuchi/developing-with-docker/-/tree/feature/k8s-in-hour