🛠️

Kubernetes Essentials: Minikube and kubectl

May 5, 2025

Kubernetes Basics with Minikube and kubectl

Introduction

  • Overview of basic kubectl commands for managing Kubernetes.
  • Focus on creating and debugging pods in Minikube.

Initial Setup

  • Minikube Cluster: Set up a Minikube cluster.
  • kubectl Installation: Ensure kubectl is installed.

Basic Commands

  • Check Node Status: kubectl get nodes
    • Shows nodes in the cluster (e.g., Master node in Minikube).
  • Check Pods: kubectl get pods
    • Displays running pods. Initially, there may be none.
  • Check Services: kubectl get services
    • Lists Kubernetes services; typically starts with a default service.

Creating Deployments

  • Pod Creation
    • Pods aren't created directly; instead, use deployments.
    • Deployments manage pods and are more efficient.
  • kubectl create deployment
    • Syntax: kubectl create deployment [name] --image=[image]
    • Example: Creating an Nginx deployment.
  • Deployment Status
    • Check with kubectl get deployment and kubectl get pods.
    • Deployment creates a ReplicaSet which manages pods.

ReplicaSet and Pod Management

  • Understanding ReplicaSet
    • Manages replicas of a pod.
    • Not directly managed by the user, instead managed through deployments.
  • Scaling Pods
    • Use deployment configurations to change the number of replicas.
  • Editing Deployments
    • Use kubectl edit deployment [name] to update configurations (e.g., image version).
    • Changes in deployments automatically cascade to pods and ReplicaSets.

Debugging and Logs

  • Accessing Logs: kubectl logs [pod-name]
    • View logs from inside containers (helps in debugging).
  • Detailed Pod Information: kubectl describe pod [pod-name]
    • Provides detailed state changes and debugging info.

Interactive Terminal Access

  • kubectl exec -it [pod-name] -- [command]
    • Opens an interactive terminal session inside a container.
    • Useful for testing and debugging directly inside the pod.

Deleting Resources

  • Deleting Deployments: kubectl delete deployment [name]
    • Removes the deployment and associated pods and ReplicaSets.

Configuration Files

  • Using Configuration Files
    • Preferred method over command-line for managing Kubernetes resources.
    • Uses kubectl apply -f [file-name.yaml] to create/update resources.
  • Example Configuration File
    • Specifies resource type, name, replicas, and pod blueprint.
  • Updating Resources
    • Simply modify the configuration file and reapply it to update existing resources.
    • Kubernetes detects and updates only the changed aspects.

Conclusion

  • Overview of essential kubectl commands.
  • Demonstrated creating, editing, and deleting deployments.
  • Discussed logging, debugging, and use of configuration files.
  • Preview of future content focusing on YAML configuration syntax.

Additional Resources

  • Look forward to more detailed tutorials on configuration files.
  • Subscribe for updates on new videos.
  • Engage with questions in the comment section of videos.