Kubernetes demo with Minikube
Requirement
docker
has been installed
git
command has been installed
Note: This demo only work with machine that running on Linux
or Darwin
and have arm64
or x86_64
architecture
Assumption
We have 3 application as 3 REST-API:
- demoflaskapi
- demoflaskapi1
- demoflaskapi2
It will be accessed with domain http://demo-service-test.local
We have route following:
http://demo-service-test.local -> demoflaskapi
http://demo-service-test.local/demoflaskapi1 -> demoflaskapi1
http://demo-service-test.local/demoflaskapi2 -> demoflaskapi2
This demo following this design:
Usage
Prepare ingredients
Firstly, you must run make install
to add execute permission for install script. After that you can install minikube by
:
make install-minikube # for install minikube to run k8s in local machine
Secondly you must export some environment variable that is authentication information to push local image to Docker Registry:
export DOCKER_HUB_USER=<username> # username of docker hub or private registry
export DOCKER_HUB_PASSWORD=<password> # password of docker hub or private registry
export DOCKER_HUB_REPOSITORY=<registry-url> # username of docker hub or private registry url
To build image and push to registry use:
make build-image
After script execution successfully you can see:
Please use yellow string (image tag be pushed to registry) to replace tag name and replace registry url in application manifests:
./manifest/application/demoflaskapi.yaml
./manifest/application/demoflaskapi1.yaml
./manifest/application/demoflaskapi2.yaml
It will look like:
Cooking
Firstly, make sure minikube
has been started.
Secondly, make sure kubectl
installed, if it were not installed, run command minikube kubectl
Thirdly, create some namespace to deploy application by kubectl
:
kubectl create namespace demo-test #namespace for deploy demo application
kubectl create ingress-nginx #namespace for deploy ingress controller to handle http request and forward to service
Deploy metrics server
The metrics-server fetches resource metrics from the kubelets and exposes them in the Kubernetes API server through the Metrics API for use by the HPA and VPA To deploy metrics-server, please use command following:
kubectl apply -f manifest/metrics
To make sure ingress controller was deployed successfully use command kubectl top node
If output look like image bellow. Congratulation!
Deploy Nginx-Ingress-Controller
An ingress controller acts as a reverse proxy and load balancer. It implements a Kubernetes Ingress. The ingress controller adds a layer of abstraction to traffic routing, accepting traffic from outside the Kubernetes platform and load balancing it to Pods running inside the platform
To deploy nginx ingress controller, please use command following:
kubectl apply -f manifest/ingress-controller
To make sure ingress controller was deployed successfully use command kubectl get pod -n ingress-nginx
If output look like image bellow. Congratulation!
Deploy our application
In this demo we have 3 application that were defined by 3 manifest file in manifest/application
we will use kubectl apply -f
for each file to deploy application
kubectl apply -f manifest/application
To make sure our application was deployed successfully use command kubectl get pod -n demo-test
If output look like image below. Congratulation!
Check ingress domain deployed by kubectl get ingress -n demo-test
Output:
Add domain to host files in /etc/hosts
:
127.0.0.1 demo-service-test.local
Use minikube service
expose port to forward request from outside to ingress-nginx-controller
:
minikube service ingress-nginx-controller -n ingress-nginx --url
Output look like:
Finally, use port in first line to access to application look like:
Check horizontal pod autoscaling
Use kubectl get hpa -n demo-test
Output look like: