Showing posts with label kubernetes. Show all posts
Showing posts with label kubernetes. Show all posts

Saturday, April 1, 2023

Understanding Kubernetes Pods: A Practical Guide with Commands

Introduction:

Kubernetes, an open-source container orchestration platform, leverages the concept of Pods as its fundamental unit. Pods play a crucial role in enhancing the High Availability of hosted applications, primarily achieved through the configuration of replicas. In this blog, we'll delve into the basics of Pods, exploring their structure and functionality, along with practical examples and essential Kubernetes commands.

What Are Pods?

Pods serve as the building blocks of Kubernetes, allowing for efficient deployment and scaling of containerized applications. They can house one or more containers, tightly coupled together with shared storage and network resources. The key features of Pods include:

  • Shared Storage: Applications within a pod have access to shared volumes, defined as part of the pod's configuration, providing a mechanism for data sharing between containers.

  • Shared IP Address and Port Space: Containers within a pod share the same IP address and port space, facilitating communication via local host.

Example: Multi-Container Pod with Shared Storage

Consider a scenario where a pod contains a file puller and a web server, both utilizing a persistent volume for shared storage. This example illustrates the flexibility and power of Pods in supporting complex application architectures.

Use Cases for Pods

While pods can host vertically integrated application stacks, their primary purpose is to facilitate the co-location and co-management of helper programs. Examples include file and content management systems, data loaders, cache managers, etc.

Kubernetes Commands for Pods

  1. List all Pods in the Default Namespace:

    bash
    $ kubectl get pods
  2. List Pods in a Specific Namespace:

    bash
    $ kubectl get pods -n <namespace name>
  3. List Pods in All Available Namespaces:

    bash
    $ kubectl get pods --all-namespaces
  4. View a Pod in Watch Mode:

    bash
    $ kubectl get pod <pod> --watch
  5. View All Pods in Watch Mode:

    bash
    $ kubectl get pods -A --watch
  6. Format Output:

    • JSON Output:
      bash
      $ kubectl get pods -o json
    • YAML Output:
      bash
      $ kubectl get pods -o yaml
    • Wide Output:
      bash
      $ kubectl get pods -o wide

Conclusion:

Understanding Kubernetes Pods is essential for effectively managing containerized applications. By exploring their features and practical usage through commands, you gain insights into how Pods contribute to the scalability, flexibility, and reliability of your Kubernetes deployments. For more detailed information, refer to the official Kubernetes documentation.

Monday, November 21, 2022

Configuring Nginx Ingress Controller in Amazon EKS Cluster: A Step-by-Step Guide

Introduction:

Amazon Elastic Kubernetes Service (Amazon EKS) provides a robust platform for managing containerized applications, and one essential component for enabling external access to multiple Kubernetes services is the Ingress Controller. In this blog post, we'll explore the setup of the Nginx Ingress Controller in an Amazon EKS cluster. Before diving into the configuration, let's ensure we have the necessary prerequisites in place.

Prerequisites:

  1. AWS CLI Installation:

    • Install AWS CLI on your local machine (compatible with Windows and Linux).
  2. Kubectl Installation:

    • Install kubectl on your local machine to interact with your Kubernetes cluster.
  3. Docker Installation:

    • Install Docker on your local machine to build and manage containers.

Nginx Ingress Setup in Kubernetes:

Step 1: Connect to AWS EKS Cluster

bash
$ aws configure

Follow the prompts to enter your AWS Access Key ID, Secret Access Key, and default region.

bash
$ kubectl get ns

Verify the EKS cluster connection by listing the available namespaces.

Step 2: Clone Nginx Ingress Repository

bash
$ git clone https://github.com/nginxinc/kubernetes-ingress.git
$ cd kubernetes-ingress/deployments/

Step 3: Deploy Nginx Ingress Controller

bash
$ kubectl apply -f common/ns-and-sa.yaml
$ kubectl apply -f common/default-server-secret.yaml
$ kubectl apply -f common/nginx-config.yaml
$ kubectl apply -f rbac/rbac.yaml

# If Kubernetes version is >= 1.18, create an NGINX Ingress class
$ kubectl apply -f common/ingress-class.yaml

Note: Update the apiVersion in common/ingress-class.yaml if needed.

Step 4: Deploy Nginx Ingress Controller (Fixed CrashLoopBackOff Issue)

bash
$ kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml
$ kubectl apply -f common/crds/k8s.nginx.org_globalconfigurations.yaml
$ kubectl apply -f common/crds/k8s.nginx.org_policies.yaml
$ kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml
$ kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml

# Deploy the Ingress Controller
$ kubectl apply -f deployment/nginx-ingress.yaml

Step 5: Apply Configuration for Load Balancer

bash
$ kubectl apply -f service/loadbalancer-aws-elb.yaml
$ kubectl get svc --namespace=nginx-ingress

Verify the successful deployment, and note the LoadBalancer's external DNS for external access.

Common Error and Solution:

bash
$ kubectl apply -f common/ingress-class.yaml

NOTE: When applying this, you may encounter the following error:

vbnet
error: resource mapping not found for name: "nginx" namespace: "" from "common/ingress-class.yaml": no matches for kind "IngressClass" in version "networking.k8s.io/v1beta1"

Solution: Update the apiVersion: networking.k8s.io/v1 in common/ingress-class.yaml file and reapply it; it will work.

bash
$ kubectl apply -f deployment/nginx-ingress.yaml

NOTE: I Applied successfully but got a CrashLoopBackOff error.

bash
nginx-ingress nginx-ingress-5b95958c76-lcjtz 0/1 CrashLoopBackOff 4 (72s ago) 2m42s

When I checked logs/Events, I saw see below error:

less
main.go:300] Error when getting IngressClass nginx: the server could not find the requested resource

By seeing this, I understood some resources were still missing. So when I was browsing, I found that I missed the CRD creation for the ingress controller.

SOLUTION:

As I mentioned, I installed the below files, and after a successful deployment, it worked fine.

bash

   $ kubectl apply -f common/crds/k8s.nginx.org_virtualserverroutes.yaml 

   $ kubectl apply -f common/crds/k8s.nginx.org_globalconfigurations.yaml 

   $ kubectl apply -f common/crds/k8s.nginx.org_policies.yaml 

   $ kubectl apply -f common/crds/k8s.nginx.org_transportservers.yaml 

   $ kubectl apply -f common/crds/k8s.nginx.org_virtualservers.yaml


Error: CrashLoopBackOff for Nginx Ingress Controller Pods

If you encounter a CrashLoopBackOff error for the Nginx Ingress Controller Pods, check the logs/events for the following error:

bash
main.go:300] Error when getting IngressClass nginx: the server could not find the requested resource

Solution:

Update the apiVersion: networking.k8s.io/v1 in common/ingress-class.yaml file, and reapply it.

Conclusion:

Configuring the Nginx Ingress Controller in an Amazon EKS cluster is a crucial step for enabling external access to your Kubernetes services. By following this step-by-step guide, addressing potential errors, and applying the provided solutions, you can successfully deploy and manage your Ingress Controller. This enhances the scalability and accessibility of your containerized applications. For more details, refer to the official NGINX documentation

Featured Post

Ansible Tool Introduction

                                                                                                                                    Next ...