🚢📦🖥️ Lesson 3 - Getting Started with Minikube

Introduction

In Kubernetes, understanding core concepts such as Pods, ReplicaSets, and Deployments is essential for effectively managing and orchestrating containerized applications. These concepts form the foundation of Kubernetes, enabling scalable, resilient, and manageable applications. This lesson will delve into these core concepts and more, providing a comprehensive understanding of their roles, functions, and interactions.


Pre-requisites

  • Minikube Installation: Make sure you have Minikube installed on your machine. You can download and install it from Minikube's official documentation.
  • Kubectl Installation: Ensure kubectl is installed and configured to interact with your Minikube cluster. You can install kubectl from Kubernetes' official documentation.
  • Docker Installation: Ensure Docker is installed and running on your machine. You can download and install Docker Desktop from Docker's official website.
  • Internet Connectivity: Ensure you have a stable internet connection to download necessary images and resources during the deployment process.
  • Basic Command Line Knowledge: Familiarize yourself with basic command line operations as you'll be executing several commands in the terminal.

Verification

Verify your installations with the following commands:

  • minikube version
    This command should display the installed version of Minikube.
  • kubectl version --client
    This command should display the installed version of kubectl.
  • docker --version
    This command should display the installed version of Docker.

Phase I: Cluster Cleanup

  • minikube stop --profile=spn-cluster-2 --alsologtostderr=false --v=0
    This command stops the Minikube cluster named spn-cluster-2. The --alsologtostderr=false --v=0 options reduce the verbosity of the output. The expected outcome is a confirmation message indicating that the Minikube cluster has been stopped. If the cluster does not exist, you may receive an error message indicating that the profile is not found.
  • minikube delete --profile=spn-cluster-2 --alsologtostderr=false --v=0
    This command deletes the Minikube cluster named spn-cluster-2. The --alsologtostderr=false --v=0 options reduce the verbosity of the output. The expected outcome is a message confirming that all traces of the specified Minikube cluster have been removed. If the cluster does not exist, a message will indicate that the profile does not exist but has been removed anyway.

Phase II: NGINX Deployment and Access

  • minikube start --profile=spn-cluster-2 --alsologtostderr=false --v=0
    This command starts the Minikube cluster named spn-cluster-2. The --alsologtostderr=false --v=0 options reduce the verbosity of the output. The expected outcome is that Minikube will initialize and set up a new Kubernetes cluster using the specified profile. You will see output messages indicating the progress of the cluster's creation and readiness.
  • kubectl create deployment nginx --image=nginx
    This command creates a Kubernetes Deployment for NGINX using the nginx image. The expected outcome is that a deployment named nginx will be created, and you will see a confirmation message indicating its creation. This deployment manages a set of identical pods running the NGINX container.

Service YAML File

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: default
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
      nodePort: 31000
  type: NodePort
Save the above content to a file named nginx-service.yaml. This YAML file defines a Kubernetes Service that exposes the NGINX deployment. The service listens on port 80 and forwards traffic to port 80 on the NGINX pods. The nodePort field specifies the external port (31000) on each node that forwards to the service.
  • kubectl apply -f nginx-service.yaml
    This command applies the configuration defined in the nginx-service.yaml file, creating the Service to expose the NGINX deployment. The expected outcome is a confirmation message indicating that the service has been created.
  • kubectl get pods
    This command retrieves and displays the status of all pods in the default namespace. The expected outcome is a list of pods showing their statuses (e.g., Running, Pending). This helps verify that the NGINX pod is up and running.
  • kubectl describe pod <nginx-pod-name> kubectl describe pod nginx-676b6c5bbc-wb5wg
    This command provides detailed information about the specified pod, including its status, events, and any error messages. Replace <nginx-pod-name> with the actual pod name from the previous command. This helps diagnose any issues if the pod is not running.
  • kubectl logs <nginx-pod-name>
    This command retrieves the logs of the specified pod, which can help identify any issues preventing the pod from running correctly. Replace <nginx-pod-name> with the actual pod name.
  • kubectl delete deployment nginx kubectl create deployment nginx --image=nginx
    These commands delete the existing NGINX deployment and recreate it. The expected outcome is that the deployment will be recreated, potentially resolving any configuration issues.
  • kubectl get svc nginx -n default
    This command retrieves and displays the status of the NGINX service. The expected outcome is a list showing the NGINX service with its assigned nodePort.
  • minikube service nginx --profile=spn-cluster-2 --url
    This command retrieves the URL to access the NGINX service via Minikube. The expected outcome is a URL that can be used to access the NGINX Welcome Page in a web browser.

Phase III: Kubernetes Dashboard Setup

  • kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
    This command deploys the Kubernetes Dashboard by applying the recommended configuration from the provided URL. The expected outcome is a confirmation message indicating that the necessary resources for the dashboard have been created.

Admin User YAML File

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: admin-user
    namespace: kubernetes-dashboard
Save the above content to a file named admin-user.yaml. This YAML file defines an Admin User ServiceAccount and a ClusterRoleBinding to grant cluster-admin privileges to the admin-user in the kubernetes-dashboard namespace. This user will be used to log in to the Kubernetes Dashboard.
  • kubectl apply -f admin-user.yaml
    This command applies the configuration defined in the admin-user.yaml file, creating the Admin User and granting the necessary permissions. The expected outcome is a confirmation message indicating that the ServiceAccount and ClusterRoleBinding have been created.
  • kubectl -n kubernetes-dashboard create token admin-user
    This command generates and retrieves an authentication token for the admin-user. The expected outcome is a token string that you will use to log in to the Kubernetes Dashboard. Save this token as you will need it for the next steps.
  • kubectl proxy --port=32000
    This command starts a proxy server that enables access to the Kubernetes Dashboard. By specifying the --port=32000 option, the proxy will listen on port 32000. The expected outcome is a running proxy server ready to handle requests to the dashboard.
  • Access the Kubernetes Dashboard
    Open your web browser and navigate to: http://localhost:32000/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/. The expected outcome is that the URL opens the Kubernetes Dashboard login page in your browser.
  • Log in to the Dashboard
    Use the token retrieved in Command 4 to log in to the Kubernetes Dashboard. The expected outcome is successful authentication, allowing you to access and manage your Kubernetes cluster through the dashboard.

Phase IV: Clean-Up

  • kubectl delete -f nginx-service.yaml
    This command deletes the NGINX Service that was created using the nginx-service.yaml file. The expected outcome is a confirmation message indicating that the service has been deleted. This ensures that there are no lingering services consuming resources.
  • kubectl delete deployment nginx
    This command deletes the NGINX Deployment, including all associated pods. The expected outcome is a confirmation message indicating that the deployment has been deleted. This cleans up the deployment and its resources.
  • kubectl delete -f admin-user.yaml
    This command deletes the Admin User ServiceAccount and the ClusterRoleBinding created by the admin-user.yaml file. The expected outcome is a confirmation message indicating that the ServiceAccount and ClusterRoleBinding have been deleted. This removes the admin user and its permissions.
  • kubectl delete -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
    This command deletes the Kubernetes Dashboard deployment that was applied from the provided URL. The expected outcome is a confirmation message indicating that the resources related to the Kubernetes Dashboard have been deleted. This ensures that the dashboard and its associated resources are cleaned up.
  • minikube stop --profile=spn-cluster-2
    This command stops the Minikube cluster named spn-cluster-2. The expected outcome is a confirmation message indicating that the Minikube cluster has been stopped. This ensures that the cluster is not running and consuming resources.
  • minikube delete --profile=spn-cluster-2
    This command deletes the Minikube cluster named spn-cluster-2. The expected outcome is a confirmation message indicating that all traces of the specified Minikube cluster have been removed. This ensures that the environment is fully cleaned up.

Summary

In this lesson, we successfully set up Minikube, deployed an NGINX application, and exposed it to the internet. We also set up the Kubernetes Dashboard for easy cluster management. This hands-on experience helps solidify your understanding of Kubernetes basics and prepares you for more advanced topics.

Key Takeaways

  • Minikube provides a local Kubernetes cluster for development and testing.
  • Deploying applications with Minikube follows similar steps as deploying them on a production Kubernetes cluster.
  • Services in Kubernetes allow you to expose your applications to the network.
  • Kubernetes Dashboard provides a user-friendly interface for managing your cluster.

Explore the contents of the other lectures - by click a lecture.

Lectures:

S No
Lecture
Topics
1
Introduction to Kubernetes Overview, Concepts, Benefits
2
Getting Started with K8s + Kind Installation, Configuration, Basic Commands
3
Getting Started with K8s + Minikube Installation, Configuration, Basic Commands
4
Kubernetes Architecture Control Plane, Nodes, Components
5
Core Concepts Pods, ReplicaSets, Deployments
6
Service Discovery and Load Balancing Services, Endpoints, Ingress
7
Storage Orchestration Persistent Volumes, Persistent Volume Claims, Storage Classes
8
Automated Rollouts and Rollbacks Deployment Strategies, Rolling Updates, Rollbacks
9
Self-Healing Mechanisms Probes, Replication, Autoscaling
10
Configuration and Secret Management ConfigMaps, Secrets
11
Resource Management Resource Quotas, Limits, Requests
12
Advanced Features and Use Cases DaemonSets, StatefulSets, Jobs, CronJobs
13
Networking in Kubernetes Network Policies, Service Mesh, CNI Plugins
14
Security Best Practices RBAC, Network Policies, Pod Security Policies
15
Custom Resource Definitions (CRDs) Creating CRDs, Managing CRDs
16
Helm and Package Management Helm Charts, Repositories, Deploying Applications
17
Observability and Monitoring Metrics Server, Prometheus, Grafana
18
Scaling Applications Horizontal Pod Autoscaling, Vertical Pod Autoscaling
19
Kubernetes API and Clients kubectl, Client Libraries, Custom Controllers
20
Multi-Tenancy and Cluster Federation Namespaces, Resource Isolation, Federation V2
21
Cost Optimization Resource Efficiency, Cost Management Tools
22
Disaster Recovery and Backups Backup Strategies, Tools, Best Practices
Prompt Engineering
In the dynamic world of containers, Kubernetes is the captain that navigates through the seas of scale, steering us towards efficiency and innovation.😊✨ - The Alchemist "

GitHub Link: 
Tags:
  • Kubernetes
  • K8s
  • Container Orchestration
  • Cloud Native
  • Docker
  • kubectl
  • Kubernetes Architecture
  • Control Plane
  • Nodes
  • Services
  • Pods
  • ReplicaSets
  • Deployments
  • Service Discovery
  • Load Balancing
  • Storage Orchestration
  • Persistent Volumes
  • Volume Claims
  • Storage Classes
  • Rollouts
  • Rollbacks
  • Self-Healing
  • ConfigMaps
  • Secrets
  • Resource Management
  • Quotas
  • Limits
  • Advanced Features
  • Networking
  • RBAC
  • Network Policies
  • Pod Security
  • CRDs
  • Helm
  • Monitoring
  • Prometheus
  • Grafana
  • Scaling
  • API Clients
  • Multi-Tenancy
  • Cluster Federation
  • Cost Optimization
  • Disaster Recovery
  • Backups
Share Now:
Last Updated: December 15, 2024 14:31:41