Getting Started with Minikube
Minikube Tips and tricks

Getting Started with Minikube and Kubernetes: Creating and Exposing a Deployment
When working with Kubernetes locally, Minikube provides an easy-to-use environment for spinning up clusters. In this tutorial, you will learn how to create a Kubernetes deployment, expose it as a service, and access the service via the terminal.
Prerequisites
- Installed Minikube
- Installed kubectl (Kubernetes CLI)
Step 1: Create a Deployment
The first step is to create a Kubernetes deployment. We will use a simple echo server for this purpose.
kubectl create deployment hello-minikube1 --image=kicbase/echo-server:1.0
This command will create a deployment called hello-minikube1
using the kicbase/echo-server
Docker image.
Step 2: Expose the Deployment
To make this deployment accessible, you need to expose it as a NodePort service:
kubectl expose deployment hello-minikube1 --type=NodePort --port=8080
The --type=NodePort
flag allows external access to the service via a random high port on the node.
Step 3: Retrieve Service Information
To get details about the exposed service, run:
kubectl get svc
This will show output similar to the following:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube1 NodePort 10.104.246.206 <none> 8080:32342/TCP 12s
Here, the service is exposed on port 32342
.
Step 4: Access the Service
You can now access the service using Minikube’s built-in command:
minikube service hello-minikube1 --url
This will give you the URL to access the echo server, something like:
http://192.168.49.2:32342
Step 5: Verify the Service
To confirm that the service is up and running, open another terminal and use the curl command:
curl http://192.168.49.2:32342
You should see a response similar to:
Request served by hello-minikube1-67bf99b564-fwrrv
This confirms that your deployment is running and accessible.
Step 6: Inspect the NodePort
You can further verify the NodePort being used with the following command:
kubectl get service hello-minikube1 --output='jsonpath="{.spec.ports[0].nodePort}"'
This outputs the NodePort (32342
in this case).
Step 7: Tunneling with Docker
If you need to establish a secure tunnel to your Minikube cluster via SSH, use the following command:
ps -ef | grep docker@127.0.0.1
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -N docker@127.0.0.1 -p 55972 -i /Users/FOO/.minikube/machines/minikube/id_rsa -L TUNNEL_PORT:CLUSTER_IP:TARGET_PORT
This command will open a tunnel to your Minikube cluster for advanced use cases.
Bonus: Load Balancing with Minikube
Minikube also provides load balancing capabilities. You can access a service using the following command:
minikube service my-httpbin --url
This is a convenient way to simulate production-level load balancing scenarios in your local environment.
Conclusion
By following this guide, you’ve successfully created a Kubernetes deployment using Minikube, exposed it as a service, and accessed it using simple terminal commands. This process is an excellent starting point for learning more about Kubernetes and how it handles deployments, services, and load balancing.