Reading Time: 3 minutes
Kubernetes Basic commands
Table of Contents
What is Kubernetes?
Kubernetes, an open-source container orchestration platform, simplifies container deployment and management. For beginners, mastering fundamental Kubernetes commands is crucial. This article explores essential commands, providing a solid foundation for navigating the Kubernetes ecosystem.
Prerequisites:
Before diving into Kubernetes commands, ensure you have a running Kubernetes cluster and kubectl
(Kubernetes command-line tool) installed on your machine.
Kubernetes Basic commands
1. Viewing Cluster Information:
$ kubectl cluster-info
Understanding cluster details, such as the Kubernetes master and services, is the first step. This command provides essential cluster information.
$ kubectl get pods
How to get Kubernetes PODS
$ kubectl get pods
Pods are the fundamental units in Kubernetes. This command displays information about running pods, including their names, status, and restart counts.
How to get Kubernetes nodes
$ kubectl get nodes
Nodes are the individual servers within your cluster. Listing nodes gives an overview of the available resources and their status.
How to Kubenetes get logs
$ kubectl logs podname --tail=100
Viewing Services
$ kubectl get services
$ kubectl get services
Services enable communication between different parts of your application. Listing services provides insights into their type, cluster IP, and external endpoints.
Describing Objects:
$ kubectl describe <resource_type> <resource_name>
For in-depth information about a specific resource (pod, service, etc.), use describe
. Replace <resource_type>
and <resource_name>
with the desired resource type and name.
Creating a Deployment:
$ kubectl create deployment <deployment_name> --image=<image_name>
Deployments manage application instances. This command creates a deployment with the specified name and container image.
Scaling Deployments:
$ kubectl scale deployment <deployment_name> –replicas=<desired_replica_count>
Scaling deployments adjusts the number of replicas. This command scales the specified deployment to the desired number of replicas.
Updating Deployments:
$ kubectl set image deployment/<deployment_name> <container_name>=<new_image_version>
Updating deployments involves changing container images. This command updates the container image for a specific deployment.
Deleting Resources:
kubectl delete <resource_type> <resource_name>
Removing resources is a common operation. Use this command to delete pods, services, or any other Kubernetes resource.
Running Commands in Pods:
$ kubectl exec -it <pod_name> — /bin/sh
Accessing a pod’s shell is crucial for troubleshooting. This command opens an interactive shell in the specified pod.
Port Forwarding:
$ kubectl port-forward <pod_name> <local_port>:<pod_port>
Port forwarding facilitates local access to a pod. This command forwards traffic from a local port to a specific port in the pod.
Applying YAML Manifests:
kubectl apply -f <filename.yaml>
Defining Kubernetes resources using YAML manifests is common. This command applies the specified YAML file to create or update resources.
What are the fundamental Kubernetes commands for beginners?
Discover essential Kubernetes commands for beginners in this guide. From viewing cluster information to managing pods and services, these commands form the foundation for navigating the Kubernetes ecosystem.
Q: What is the ‘kubectl cluster-info’ command used for in Kubernetes?
A: The ‘kubectl cluster-info’ command provides essential details about the Kubernetes cluster, including the master and services. What purpose does this command serve for users exploring a Kubernetes environment?
Q: How can I list all the nodes in a Kubernetes cluster using ‘kubectl’?
A: To list all nodes in a Kubernetes cluster, the ‘kubectl get nodes’ command is employed. How does this command assist users in understanding the cluster’s resources and status?
Q: What does the ‘kubectl get pods’ command do in Kubernetes?
A: The ‘kubectl get pods’ command is crucial for exploring pods, the fundamental units in Kubernetes. How does this command display information about running pods, aiding in monitoring and management?
Conclusion: Navigating Kubernetes begins with mastering fundamental commands. From exploring cluster details to managing resources, these commands lay the groundwork for efficient Kubernetes operations. As you delve deeper, these basics will serve as your compass in the vast Kubernetes landscape. We hope this tutorial “Kubernetes Basic commands” explains you well.
You can find all our tutorials on Linkedin