DEV Community

bismaakram
bismaakram

Posted on

kubectl Made Simple: Using Imperative Commands in Kubernetes

Kubernetes can feel overwhelming at first, but kubectl makes interacting with your cluster simple and powerful. In this post, we’ll explore imperative commands in Kubernetes—hands-on instructions you run directly with kubectl to create, update, and manage resources.

Fundamentals of Kubernetes

  1. Cluster – A set of machines (nodes) that run containerized applications managed by Kubernetes.

  2. Node – A worker machine (virtual or physical) where containers are executed.

  3. Pod – The smallest deployable unit in Kubernetes. A Pod represents one or more containers that share networking and storage.

  4. Replica set – Maintains a stable set of replica pods running at any given time. It is often used to guarantee the availability of a specified number of identical pods.

  5. Service – A stable networking abstraction that exposes Pods and enables communication within or outside the cluster.

  6. Deployment – A controller that manages Pods and ensures the desired number of replicas are running.

Get Worker Nodes status
You can refer to my previous tutorial on how to create a eksctl cluter and managed node group.

kubectl get nodes -o wide
Enter fullscreen mode Exit fullscreen mode

Create a Pod

kubectl run my-first-pod --image stacksimplify/kubenginx:1.0.0
Enter fullscreen mode Exit fullscreen mode

In order to access the application externally from the internet, we need to expose the Pod with a NodePort Service.

kubectl expose pod my-first-pod  --type=NodePort --port=80 --name=my-first-service
kubectl get svc
Enter fullscreen mode Exit fullscreen mode

Access the application using public IP

Connect to Container in a Pod

kubectl exec -it my-first-pod -- /bin/bash
Enter fullscreen mode Exit fullscreen mode

Clean-Up

kubectl get all
kubectl delete svc my-first-service
kubectl delete pod my-first-pod
kubectl get all
Enter fullscreen mode Exit fullscreen mode

Thank you!! 🙌

Top comments (0)