Showing posts with label Kubernetes. Show all posts

Kubernetes kubectl Commands

 

🔧 1. Cluster Info and Context

kubectl cluster-info # Display cluster endpoint info kubectl config get-contexts # List contexts kubectl config use-context <context-name> # Switch to a specific context kubectl get nodes # List all worker/master nodes kubectl describe node <node-name> # Detailed info about a node

📦 2. Pods

kubectl get pods # List all pods in the current namespace kubectl get pods -A # List all pods in all namespaces kubectl describe pod <pod-name> # Show detailed info about a pod kubectl logs <pod-name> # View logs of a pod kubectl logs -f <pod-name> # Stream logs kubectl exec -it <pod-name> -- /bin/bash # Get shell access inside a pod kubectl delete pod <pod-name> # Delete a pod

Quick Guide to Kubernetes

Kubernetes is a container orchestration system. It helps you deploy, scale, manage, and heal your containerized applications (like Docker containers) automatically.


⚙️ High-Level Architecture:

+------------------+ | User (You) | +--------+---------+ | v +--------+----------+ +----------------+ | Kubernetes API | <----> | kubectl | | (Control Plane)| +----------------+ +--------+----------+ | v +--------+----------+---------------------------+ | Scheduler | Controller Manager | etcd (DB) | +-----------+--------------------+--------------+ | v +--------+----------+ | Kubelet | <--- On each worker node | (runs on nodes) | +--------+----------+ | v +------------------+ | Container Runtime (Docker/containerd) | | Runs Pods with app containers inside | +------------------+

Step-by-step guide to install Kubernetes (K8s) on Red Hat Enterprise Linux (RHEL) 9.5

 Here’s a step-by-step guide to install Kubernetes (K8s) on Red Hat Enterprise Linux (RHEL) 9.5, using kubeadm, the official Kubernetes tool.


✅ Prerequisites

  1. Root / sudo access

  2. Swap disabled

  3. Docker or containerd installed

  4. Firewall open for Kubernetes ports

  5. Unique hostname, static IP, and DNS resolution for each node


🔧 Step 1: Disable Swap

sudo swapoff -a sudo sed -i '/swap/d' /etc/fstab

Docker vs Kubernetes

 Docker and Kubernetes are both essential tools in the container ecosystem, but they serve different purposes and are often used together in modern software development and deployment. Here’s a breakdown of each and a comparison of their functionalities and roles.

What is Docker?

Docker is a platform for developing, shipping, and running applications in containers. Containers are lightweight, portable units that package application code along with all its dependencies, making it easy to run applications consistently across different environments.

Key Docker components:

  • Docker Engine: The runtime that builds, runs, and manages containers on a host.
  • Docker Images: Templates used to create containers; they contain application code and dependencies.
  • Docker Containers: Running instances of Docker images that provide isolated environments for applications.
  • Docker Compose: A tool for defining and running multi-container Docker applications, useful for developing and testing services locally.

What is Kubernetes?

Kubernetes is a container orchestration platform designed to manage, scale, and deploy containerized applications across clusters of machines. While Docker handles individual containers, Kubernetes automates the deployment, scaling, and management of containerized applications across multiple hosts, ensuring high availability and scalability.

Key Kubernetes components:

  • Cluster: A collection of nodes (hosts) where Kubernetes manages containers.
  • Pods: The smallest deployable units in Kubernetes, typically a single container or a group of closely related containers.
  • Nodes: The physical or virtual machines that host the containers.
  • Control Plane: Manages the cluster, schedules workloads, and monitors the cluster’s state.
  • Services: Provide load balancing and service discovery for pods, ensuring that applications remain accessible.

Docker vs. Kubernetes

What is Kubernetes?

 Kubernetes (often abbreviated as "K8s") is an open-source platform designed for managing containerized applications in a distributed environment. Originally developed by Google, it is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes automates deployment, scaling, and operations of application containers across clusters of hosts, providing a container-centric infrastructure.

Key Components of Kubernetes

  1. Cluster: A Kubernetes cluster is a set of nodes (machines) that run containerized applications. It consists of at least one control plane and several worker nodes.

  2. Control Plane: The control plane manages the Kubernetes cluster and coordinates its activities. Key components include:

    • API Server: The primary management point, where users, other components, and external tools communicate with Kubernetes.
    • etcd: A key-value store that maintains the cluster’s state, configuration, and metadata.
    • Controller Manager: Monitors the cluster’s desired state and ensures it matches the actual state, handling tasks like node management, replication, and endpoint management.
    • Scheduler: Allocates containers to available nodes based on resource requirements and constraints.