Deploy a simple Pod using the kubectl run
command:
kubectl run hello-minikube
To get general information about the cluster:
kubectl cluster-info
List all nodes in the cluster:
kubectl get nodes
Run a Pod with a specified image:
kubectl run nginx --image nginx
(This pulls the image from Docker Hub.)
Describe a specific Pod to get detailed information:
kubectl describe pod webapp
Delete a specific Pod:
kubectl delete pod webapp
Use the --dry-run=client -o yaml
option to create a manifest file for a Pod:
kubectl run redis --image=redis123 --dry-run=client -o yaml > redis-definition.yaml
Use kubectl create -f
to create the resource from the manifest file:
kubectl create -f redis-definition.yaml
To verify if the Pod is created, run:
kubectl get pods
Use the kubectl edit
command to update the Pod image:
kubectl edit pod redis
Alternatively, if using a manifest file, update the image directly in the YAML file (using vi
or nano
) and run:
kubectl apply -f redis-definition.yaml
To see detailed information about a specific Pod:
kubectl describe pod newpods-<id>
Or, to view the Pod placement on a node:
kubectl get pods -o wide
Export the YAML definition of a Pod:
kubectl get pod <pod-name> -o yaml > pod-definition.yaml
List all Pods in the kube-system
namespace:
kubectl get pods --namespace=kube-system
Run the command to get the exact number of namespaces:
kubectl get ns --no-headers | wc -l
Set the default namespace for the current context:
kubectl config set-context $(kubectl config current-context) --namespace=dev
Get Pods from the research
namespace:
kubectl -n research get pods
Create a Pod in the finance
namespace:
kubectl run redis --image=redis -n finance
Search for a specific Pod across all namespaces:
kubectl get pods --all-namespaces | grep blue
Or, to get Pods across all namespaces:
kubectl get pods -A
Get the service from the marketing
namespace:
kubectl get svc -n=marketing
kubectl run nginx --image=nginx
kubectl create -f /tmp/kubectl-edit-ccvrq.yaml