Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Kubernetes - Basic Commands

Getting Started with Kubernetes

Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. This guide introduces basic Kubernetes commands to help you manage your Kubernetes clusters.

Key Points:

  • Kubernetes commands are used to interact with and manage your clusters.
  • The kubectl command-line tool is used to execute Kubernetes commands.
  • Understanding basic commands is essential for effectively managing your Kubernetes environment.

kubectl Basics

kubectl is the command-line tool for interacting with Kubernetes clusters. Here are some basic commands to get you started:

# Check the version of kubectl
kubectl version

# Get cluster information
kubectl cluster-info

# List all nodes in the cluster
kubectl get nodes
                

Managing Pods

Pods are the smallest deployable units in Kubernetes. Here are some commands to manage pods:

# List all pods in the default namespace
kubectl get pods

# Get detailed information about a specific pod
kubectl describe pod 

# Delete a pod
kubectl delete pod 
                

Managing Deployments

Deployments are used to manage the deployment of applications. Here are some commands to manage deployments:

# List all deployments in the default namespace
kubectl get deployments

# Get detailed information about a specific deployment
kubectl describe deployment 

# Scale a deployment
kubectl scale deployment  --replicas=3

# Delete a deployment
kubectl delete deployment 
                

Managing Services

Services provide network access to a set of pods. Here are some commands to manage services:

# List all services in the default namespace
kubectl get services

# Get detailed information about a specific service
kubectl describe service 

# Delete a service
kubectl delete service 
                

Using Namespaces

Namespaces provide a way to divide cluster resources between multiple users. Here are some commands to manage namespaces:

# List all namespaces
kubectl get namespaces

# Create a new namespace
kubectl create namespace 

# Delete a namespace
kubectl delete namespace 
                

Getting Logs

You can retrieve logs from your pods to troubleshoot and monitor your applications. Here are some commands to get logs:

# Get logs from a specific pod
kubectl logs 

# Get logs from a specific container in a pod
kubectl logs  -c 
                

Executing Commands in a Pod

You can execute commands directly inside a pod. Here are some commands to do that:

# Execute a command in a specific pod
kubectl exec -it  -- 

# Example: Open a shell in a specific pod
kubectl exec -it  -- /bin/bash
                

Conclusion

This guide introduced basic Kubernetes commands to help you manage your Kubernetes clusters. By mastering these commands, you can effectively interact with and manage your Kubernetes environment.