peter (admin) -

Creating Your First Kubernetes Cluster with Minikube
We have completed the basic setup of our Kubernetes learning environment. Docker, Minikube, and kubectl are installed, so we are now ready to create our first Kubernetes cluster using Minikube.
In this section, we will start the cluster, understand what Minikube does during the startup process, and verify that Kubernetes is running correctly.
Starting the Minikube Cluster
Open your terminal or PuTTY session and connect to the Linux machine.
To create and start the Kubernetes cluster using Docker, run:
minikube start --driver=docker
The important option here is:
--driver=docker
This tells Minikube to use Docker as its driver.
Instead of creating a separate traditional virtual machine, Minikube creates its Kubernetes node using Docker.
The basic structure looks like this:
Linux Host
|
v
Docker
|
v
Minikube
|
v
Kubernetes Node
|
+---- API Server
+---- Scheduler
+---- Controller Manager
+---- etcd
+---- Kubelet
+---- CoreDNS
Using the Docker driver provides a relatively lightweight environment that is particularly useful for Kubernetes development and learning.
The Minikube Startup Process
After running:
minikube start --driver=docker
Minikube begins creating the cluster.
The first startup normally takes longer than subsequent starts because Minikube may need to download several images and Kubernetes components.
During this process, you will see information appearing in the terminal showing the different stages of cluster creation.
Memory Requirements
Minikube checks whether your system has enough resources to create the cluster.
If your machine has limited memory, Minikube may display a warning.
For a learning environment, 4 GB of system RAM may be sufficient for a small cluster, although having more memory available will provide a better experience.
Remember that the host operating system, Docker, Minikube, Kubernetes system components, and your application Pods all require memory.
For example:
Host Operating System
|
+---- Docker
|
+---- Minikube
|
+---- Kubernetes Components
|
+---- Application Pods
As you begin running more applications, the memory requirements will increase.
Downloading Kubernetes Images
During the first startup, Minikube downloads the images required to create the Kubernetes environment.
You may see references to preloaded Kubernetes images.
These contain Kubernetes components and other resources that Minikube needs to construct the cluster.
Minikube may also download the KIC base image.
KIC stands for:
Kubernetes in Container
When using the Docker driver, this base image provides the environment in which the Minikube Kubernetes node runs.
The download time depends on the speed of your internet connection and whether the required images already exist locally.
Creating the Kubernetes Node
Once the required images are available, Minikube begins configuring the Kubernetes node.
It performs tasks such as:
-
Creating the Docker-based node
-
Configuring networking
-
Starting Kubernetes control-plane components
-
Configuring the kubelet
-
Configuring cluster DNS
-
Configuring storage
-
Creating kubectl configuration
Minikube automates these operations for us.
This is one of the reasons it is such a useful tool when first learning Kubernetes.
Cluster Created
Once Minikube has finished, it will display a message indicating that the cluster has been successfully created and kubectl has been configured to use it.
Our environment now looks approximately like this:
Linux
|
v
Docker
|
v
Minikube
|
v
+-----------------------------+
| Kubernetes Cluster |
| |
| API Server |
| Scheduler |
| Controller Manager |
| etcd |
| Kubelet |
| CoreDNS |
| Storage |
+-----------------------------+
Our first local Kubernetes cluster is now running.
Check Minikube Status
The next step is to verify the cluster.
Run:
minikube status
You should see information similar to:
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
Let's look at what these values mean.
Control Plane
The Minikube node acts as the Kubernetes control plane.
The control plane contains the components responsible for managing the Kubernetes cluster.
These include components such as:
-
API server
-
Scheduler
-
Controller manager
-
etcd
In a Minikube learning environment, control-plane and workload responsibilities can exist on the same node.
Host: Running
If Minikube reports:
host: Running
the Minikube environment itself is running.
If the host is stopped, the Kubernetes components inside it will not be available.
Kubelet: Running
You should also see:
kubelet: Running
The kubelet is the Kubernetes agent responsible for managing Pods and containers on a node.
It monitors the workloads assigned to its node and works with the container runtime to ensure that the required containers are running.
The kubelet continually works toward making the actual state of the node match the desired state recorded by Kubernetes.
API Server: Running
Another important result is:
apiserver: Running
The Kubernetes API server is the central communication point for the cluster.
When we execute a command such as:
kubectl get pods
kubectl communicates with the API server.
The API server processes the request and returns the requested information.
The communication flow looks like this:
User
|
v
kubectl
|
| HTTPS
v
API Server
|
v
Kubernetes Cluster
If the API server is not running, kubectl will not be able to manage the cluster normally.
Kubeconfig
Minikube should also report that the kubeconfig is configured.
For example:
kubeconfig: Configured
The kubeconfig file contains information kubectl needs to communicate with Kubernetes.
The default location is usually:
~/.kube/config
You can inspect the current kubectl context with:
kubectl config current-context
For our Minikube environment, this should normally return:
minikube
This tells us that kubectl is currently configured to communicate with our Minikube cluster.
Check the Kubernetes Node
We can now ask Kubernetes to show its nodes:
kubectl get nodes
You should see something similar to:
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane ... ...
The most important value is:
Ready
This means Kubernetes considers the node healthy and available for workloads.
For additional information, use:
kubectl get nodes -o wide
This displays additional details such as internal IP addresses, operating-system information, kernel version, and container runtime.
Check Cluster Information
We can also ask Kubernetes for information about the cluster:
kubectl cluster-info
The output will contain an HTTPS address for the Kubernetes control plane.
For example:
Kubernetes control plane is running at https://:8443
The exact IP address depends on your Minikube configuration.
Port:
8443
is commonly used by Minikube for access to the Kubernetes API server.
Communication with the API server takes place securely over HTTPS.
What Happens When We Use kubectl?
Suppose we run:
kubectl get pods
The process can be simplified as:
kubectl
|
| HTTPS request
v
API Server
|
| Reads cluster state
v
Kubernetes
|
| Response
v
API Server
|
v
kubectl
|
v
Terminal Output
kubectl does not directly inspect the containers itself.
Instead, it communicates with the Kubernetes API server, which provides the requested cluster information.
CoreDNS
The cluster also contains CoreDNS, which provides DNS services inside Kubernetes.
We can see the Kubernetes system Pods with:
kubectl get pods -n kube-system
You should see a CoreDNS Pod among the results.
CoreDNS allows applications inside Kubernetes to locate Services using DNS names rather than requiring applications to know individual IP addresses.
For example, an application may communicate with a Service using a name such as:
database
rather than having to know an address such as:
10.96.x.x
This is particularly important because Kubernetes resources can be recreated and their IP addresses can change.
Check All System Pods
A useful command after creating the cluster is:
kubectl get pods -n kube-system
This allows us to see the Kubernetes system components running as Pods.
You can also view Pods across all namespaces with:
kubectl get pods -A
Ideally, the Kubernetes system Pods should show a status such as:
Running
Useful Minikube Commands
Now that our cluster exists, there are several Minikube commands worth remembering.
Check its status:
minikube status
Stop the cluster:
minikube stop
Start it again:
minikube start
View its IP address:
minikube ip
Open the Kubernetes dashboard:
minikube dashboard
If you want to completely remove the cluster:
minikube delete
Be careful with minikube delete, because it removes the Minikube cluster rather than simply stopping it.
Verifying the Complete Environment
We can perform a final series of checks:
docker --version
minikube version
kubectl version --client
minikube status
kubectl get nodes
kubectl get pods -A
kubectl cluster-info
If these commands return the expected information and our node shows:
Ready
our local Kubernetes environment is operational.
Our First Kubernetes Cluster Is Ready
We have now successfully created our first Kubernetes cluster using Minikube.
The complete environment can be summarized as:
Linux Host
|
+---- Docker
| |
| +---- Provides Minikube's container driver
|
+---- Minikube
| |
| +---- Creates the local Kubernetes cluster
|
+---- kubectl
|
+---- Communicates with the API server
|
v
Kubernetes Cluster
|
+----------+----------+
| | |
Pods Services Deployments
We can now use kubectl to communicate with the cluster and begin creating Kubernetes resources such as Pods, Deployments, and Services.
Our Kubernetes environment is active, reachable, and ready for the next stage: deploying our first application to Kubernetes.
Comments (0)
There are no comments yet. Be the first to comment.
Log in or register to leave a comment. all comments are subject to admin approval