To get the cluster info use-
kubectl cluster-info
To get list of nodes user-
kubectl get nodes
Creating Pod – imperative way
Create a POD with nginx image and name nginx in default namespace
// kubectl run <<pod name>> --image <<image in docker hub>>
kubectl run nginx --image nginx
Create a POD with nginx image and name nginx in different namespace
// kubectl run <<pod name>> --image <<image in docker hub>> -n <<namespace name>>
kubectl run nginx --image nginx -n production
Get Pods and details
Get a list of POD’s in default namespace
kubectl get pods
Get a list of POD’s in other namespace
//kubectl get pods -n <<namespace name>>
kubectl get pods -n production
Check the node of the Pod it is created-
kubectl get pods -o wide
Create POD using yaml – declarative way
// file name- pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod-yaml
spec:
containers:
- name: nginx-container-yaml
image: nginx
Create a pod declarative way-
kubectl create -f pod-definition.yaml
Deleting Pod
Delete a pod in default namespace
// kubectl delete pod <<pod-name>>
kubectl delete pod nginx-pod-yaml
Delete all pods in default namespace
kubectl delete --all pods
Delete a pod in custom namespace
//kubectl delete pod <<pod-name>> -n <<namespace-name>>
kubectl delete pod nginx-pod-yaml -n development
Delete all pods in custom namespace
//kubectl delete --all pods -n <<namespace-name>>
kubectl delete --all pods -n development