In this project, you will set up a local Kubernetes cluster using Minikube and deploy a sample application to get familiar with basic Kubernetes operations.
-
Minikube Installation: Follow the Minikube installation guide to install Minikube on your local machine.
-
kubectl Installation: Follow the kubectl installation guide to install kubectl, the command-line tool for interacting with Kubernetes clusters.
-
Start Minikube and create a local Kubernetes cluster:
minikube start
This command will start a local Kubernetes cluster using a virtual machine or container.
-
Deploy a simple web server application:
kubectl create deployment hello-minikube --image=kicbase/echo-server:1.0
This command creates a deployment named
hello-minikube
using theechoserver
image.
-
Expose the deployment as a service to make it accessible:
kubectl expose deployment hello-minikube --type=NodePort --port=8080
This command creates a service of type
NodePort
that maps port 8080 of the service to a port on the node. -
Use kubectl to forward the port:
kubectl port-forward service/hello-minikube 7080:8080
This command forwards port 8080 of the service to port 7080 on your localhost, making the application accessible at http://localhost:7080/.
-
Alternatively, get the URL to access the application:
minikube service hello-minikube
This command provides the URL where you can access the sample application running in your Minikube cluster.
-
Create a deployment:
kubectl create deployment balanced --image=kicbase/echo-server:1.0
-
Expose the deployment as a LoadBalancer service:
kubectl expose deployment balanced --type=LoadBalancer --port=8080
-
Start the tunnel to create a routable IP for the 'balanced' deployment in another window:
minikube tunnel
-
Find the routable IP by running this command and examining the EXTERNAL-IP column:
kubectl get services balanced
Your deployment is now available at
10.101.45.106:8080
.
-
Enable the ingress addon:
minikube addons enable ingress
-
Create an example deployment and service with Ingress:
-
Apply the Ingress configuration:
kubectl apply -f resources/foo-app.yaml kubectl apply -f resources/foo-service.yaml kubectl apply -f resources/bar-app.yaml kubectl apply -f resources/bar-service.yaml kubectl apply -f resources/ingress.yaml
-
Get the Minikube IP:
minikube ip
-
Access the application via the Ingress host configured in
ingress.yaml
.kubectl get ingress
curl 192.168.49.2/foo # Output: Request served by foo-app curl 192.168.49.2/bar # Output: Request served by bar-app
-
Scale the deployment to run multiple replicas:
kubectl scale deployment hello-minikube --replicas=3
This command scales the deployment to 3 replicas.
-
Update the deployment with a new image:
kubectl set image deployment/hello-minikube echo-server=kicbase/echo-server:latest
This command performs a rolling update to the deployment by changing the container image to
echo-server:latest
.