Rahul Shishodia
KubernetesSSISConnect!
  • Kubernetes
    • Components
    • Architecture
    • Kubernetes Overview and Key Benefits
    • Minikube and kubectl
    • Commands
    • YAML Configuration
  • MongoDB Deployment
  • Ingress
  • Networking
  • SQL Server Integration Services
    • Overview
  • SQL Server Data Tools
  • SSDT Installation Troubleshooting
  • Control Flow
Powered by GitBook
On this page
  • Cluster Setup and Initial Status Checks
  • Creating Kubernetes Resources
  • Creating a Deployment (Example: nginx)
  • Working with ReplicaSets
  • Editing Deployments (Example: Set Specific nginx Version)
  • Debugging and Logging
  • Interactive Debugging with exec
  • Deleting Resources
  • Managing Complexity with Configuration Files
  1. Kubernetes

Commands

Cluster Setup and Initial Status Checks

  • Minikube Cluster and kubectl:

    • Minikube cluster is used as the Kubernetes environment.

    • kubectl (command-line tool) is essential for interacting with the cluster.

  • Basic Status Commands:

    • kubectl get nodes:

      • Shows cluster nodes.

      • In Minikube, a single master node is used.

    • kubectl get pods:

      • Lists current pods.

      • Returns “No resources” if none exist.

    • kubectl get services:

      • Displays running services.

      • Shows default service if no additional ones are created.


Creating Kubernetes Resources

  • kubectl create:

    • Used for creating Kubernetes components.

    • Running kubectl create --help shows available resource types.

    • Note: Direct pod creation is not listed.

  • Pod Abstraction via Deployment:

    • In Kubernetes, pods are typically not created directly.

    • Instead, use deployments, which manage pods via replica sets.


Creating a Deployment (Example: nginx)

  • Command Syntax:

    kubectl create deployment nginx-deployment --image=nginx
    • Creates a deployment named nginx-deployment.

    • Downloads the latest nginx image from Docker Hub.

  • Deployment Verification:

    • kubectl get deployments: Checks deployment status.

    • kubectl get pods: Shows auto-generated pod with status like ContainerCreating → Running.

  • Architecture Layers:

    • Deployment → ReplicaSet → Pod → Container (Image).

    • Pod names reflect hierarchy (deployment name, replica set hash, pod-specific hash).


Working with ReplicaSets

  • Understanding ReplicaSets:

    • Created automatically when a deployment is created.

    • Manage pod replication.

    • Not typically managed directly by users.

  • Viewing ReplicaSets:

    kubectl get replicasets
    • Shows replica set linked to the deployment.


Editing Deployments (Example: Set Specific nginx Version)

  • Edit Command:

    kubectl edit deployment nginx-deployment
  • Changes Made:

    • Scroll to the image field.

    • Update image version (e.g., nginx:1.16).

    • Save changes.

  • Observed Behavior:

    • Old pod terminates.

    • New pod is created with updated image.

    • ReplicaSet is updated automatically.


Debugging and Logging

  • Logs:

    kubectl logs <pod-name>
    • Returns output of container logs inside the pod.

    • Useful for debugging application behavior.

  • Example with MongoDB Deployment:

    kubectl create deployment mongodb-deployment --image=mongo
    kubectl logs <mongodb-pod-name>
    • MongoDB logs are displayed once the container starts.

  • Describing Pod State:

    kubectl describe pod <pod-name>
    • Provides detailed state changes: image pulled, container created, container started.


Interactive Debugging with exec

  • Command for Terminal Access:

    kubectl exec -it <pod-name> -- /bin/bash
    • Opens terminal in the container as root user.

    • Enables execution of internal commands.

    • Critical for real-time troubleshooting.


Deleting Resources

  • Deleting Deployments:

    kubectl delete deployment <deployment-name>
    • Automatically deletes associated pods and replica sets.

  • Example:

    • Delete MongoDB deployment:

      kubectl delete deployment mongodb-deployment
    • ReplicaSet and pods associated with MongoDB are removed.


Managing Complexity with Configuration Files

  • Command-Line Limitation:

    • Command-line creation (e.g., kubectl create deployment) requires all options to be specified inline.

    • Becomes impractical for complex configurations.

  • Using YAML Configuration Files:

    • More scalable and manageable method.

    • Define:

      • Resource type

      • Name

      • Image

      • Additional configuration

    • Apply using:

      kubectl apply -f <filename>.yaml
    • f flag specifies the configuration file to execute.

PreviousMinikube and kubectlNextYAML Configuration