Let's read about minikube and implement k8s in our local machine
What is minikube?
Minikube is an open-source tool that facilitates running Kubernetes clusters on a local machine. Kubernetes is a popular container orchestration platform used for automating the deployment, scaling, and management of containerized applications. Minikube enables developers to set up a single-node Kubernetes cluster on their local development machine, making it easier to test and develop applications before deploying them to a larger-scale Kubernetes environment.
Key features of Minikube include:
Local Kubernetes Cluster: Minikube creates a lightweight, single-node Kubernetes cluster on your local machine, allowing developers to simulate a Kubernetes environment for testing and development purposes.
Easy Setup: Minikube simplifies the process of setting up a Kubernetes cluster by automating many of the tasks involved. It handles the installation and configuration of the necessary components, making it accessible to developers who are new to Kubernetes.
Support for Multiple Hypervisors: Minikube supports different hypervisors, including VirtualBox, VMware, Hyper-V, and others, allowing users to choose the virtualization technology that best fits their development environment.
Isolation: Running a local Kubernetes cluster with Minikube provides a controlled and isolated environment for testing applications, ensuring that changes do not impact a production environment.
Integration with kubectl: Minikube seamlessly integrates with
kubectl
, the command-line tool for interacting with Kubernetes clusters. This allows developers to use familiar commands to manage and interact with the local cluster.Add-ons and Features: Minikube supports various add-ons and features that can be enabled or disabled based on the requirements of the development or testing scenario. These add-ons may include features like the Kubernetes Dashboard, Ingress controllers, and more.
For installation, you can Visit this page
If you want to try an alternative way, you can check this.
Let's understand the concept pod
In Kubernetes, a Pod is the smallest and simplest unit in the Kubernetes object model. It represents a single instance of a running process in a cluster and is the basic building block upon which other Kubernetes abstractions are based. A Pod can encapsulate one or more containers, storage resources, and unique network IP, and it represents a logical host for those containers.
Here are key concepts related to Pods:
Container(s): A Pod can contain one or more containers, and these containers share the same network namespace, allowing them to communicate with each other using
localhost
. Containers within the same Pod can easily communicate with each other using inter-process communication mechanisms like Unix sockets or shared volumes.Shared Storage: Pods have shared storage volumes that are mounted to containers. This allows containers within the same Pod to share data and files. These volumes are ephemeral by default, meaning that their contents are lost if the Pod is rescheduled to run on a different node.
Unique IP Address: Each Pod gets its own unique IP address within the cluster. Containers within the Pod communicate using this IP address.
Lifecycle: Pods are mortal and can be created, terminated, and replaced dynamically. If a Pod dies or is rescheduled to run on a different node, a new Pod with the same specifications is created to maintain the desired state.
Atomic Unit of Deployment: In many cases, it's recommended to run a single container per Pod. However, there are scenarios where multiple tightly coupled containers are best deployed together in a single Pod, such as when they need to share resources and dependencies.
Labels and Selectors: Pods can be labeled with key-value pairs, and these labels are used by selectors to identify and group related Pods. This is crucial for services, replication controllers, and other higher-level Kubernetes abstractions to manage and interact with Pods.
Here's a simple example of a Pod manifest in YAML:
apiVersion: v1
kind: Pod
metadata:
name: example-pod
spec:
containers:
- name: nginx-container
image: nginx:latest
This example creates a Pod named example-pod
with a single container running the latest version of the Nginx web server. This is a basic illustration, and real-world scenarios may involve more complex Pod configurations and multiple containers working together to achieve a specific goal.
Create your first pod on Kubernetes through minikube with Nginx running:
To create your first Pod on Kubernetes using Minikube, you'll need to follow these steps:
Install Minikube: If you haven't installed Minikube on your machine, you can do so by following the instructions on the official Minikube documentation: Install Minikube
Start Minikube Cluster: Open a terminal and start the Minikube cluster. This command will create a single-node Kubernetes cluster on your local machine:
minikube start
Create a Pod Manifest: Create a YAML file describing your Pod. For example, let's create a simple Pod running an Nginx container. Create a file named
nginx-pod.yaml
with the following content:apiVersion: v1 kind: Pod metadata: name: multi-port-pod spec: containers: - name: nginx-container image: nginx:latest ports: - containerPort: 80 # Expose port 80 in the nginx-container - name: my-app-container image: my-app-image:latest ports: - containerPort: 8080 # Expose port 8080 in the my-app-container - containerPort: 9090 # Expose an additional port 9090
Apply the Pod Manifest: Apply the Pod manifest using the
kubectl apply
command:kubectl apply -f nginx-pod.yaml
This will create the Pod in your Minikube cluster.
Check the Status of the Pod: You can check the status of your Pod using the
kubectl get pods
command:kubectl get pods
Wait until the Pod's status changes to "Running." It may take a few moments for the container to be pulled and started.
Access the Pod: If you want to access the Nginx service running in the Pod, you can use the following command:
kubectl port-forward nginx-pod 8080:80
This command forwards local port 8080 to the Pod's port 80. You can then access the Nginx welcome page by opening a web browser and navigating to
http://localhost:8080
.Stop Minikube: Once you're done experimenting, you can stop Minikube using the following command:
minikube stop
This stops the Minikube cluster, and you can start it again when needed.
๐ Thank you for reading my blog! ๐ If you found this information helpful, drop a comment and spread the knowledge! ๐ For more Kubernetes insights and updates, feel free to follow me on:
LinkedIn: Sumit Katkar ๐
HashNode: Sumit Katkar's Blog ๐
Happy Learning! ๐