Deploying Your First Kubernetes Cluster
Now that you have Minikube installed and configured, it's time to deploy your first Kubernetes cluster. Minikube makes this process straightforward, allowing you to quickly spin up a single-node Kubernetes cluster on your local machine.
Starting a Minikube Cluster
To start a Minikube cluster, simply run the following command:
minikube start
This command will download the necessary Kubernetes components, create a virtual machine (VM), and set up the Kubernetes cluster within the VM. The process may take a few minutes, depending on your system's resources and internet connection speed.
Once the cluster is up and running, you can verify its status using the minikube status
command:
minikube status
The output should indicate that the cluster is running and ready for use.
Deploying a Sample Application
To demonstrate the deployment of a Kubernetes application using Minikube, let's deploy a simple "hello world" web application. We'll use the kubectl
command-line tool to interact with the Kubernetes cluster.
First, create a deployment for the "hello world" application:
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
This command creates a Kubernetes deployment named "hello-minikube" and pulls the necessary container image from the specified registry.
Next, expose the deployment as a Kubernetes service, making the application accessible from outside the cluster:
kubectl expose deployment hello-minikube --type=NodePort --port=8080
This command creates a NodePort service, which maps the application's port 8080 to a randomly selected port on the host machine.
To access the application, run the following command to get the URL:
minikube service hello-minikube --url
The output will provide the URL where you can access the "hello world" application from your local machine.
By following these steps, you've successfully deployed your first Kubernetes application using Minikube. This process allows you to test and experiment with Kubernetes features and deployments in a local development environment before scaling to a production-ready Kubernetes cluster.