KUBERNETES LEARNING PHASE 1 - BASIC COMMANDS
- Ankit Agrahari
- Nov 12, 2021
- 1 min read

This post will only includes scenario based Kubernetes problem and the commands/debugging steps. It will be updated whenever I learn something new.
For Installation of Kubernetes refer here: https://kubernetes.io/docs/tasks/tools/
Case 1: Get all pods in a namespace
kubectl get pods -n <namespace_name>Case 2: Get all namespaces
kubectl get namespaces
OR
kubectl get nsCase 3: Create pods with a name and image in a particular namespace
kubectl run <pod_name> --image=<image_name> -n <namespace>e.g.
kubectl run redis --image=redis -n my-namespaceCase 4: Get all pods in all the namespaces
kubectl get pods --all-namespacesCase 5: Get all replicasets
kubectl get replicasetCase 6: Create pods using yaml file
kubectl apply -f abc.yml -n namespaceabc.yaml or abc.yml file:
apiVersion: v1
kind: Pod
metadata:
name: new-pod
label:
type: linux
spec:
containers:
-name: redis
image: redisCase 7: Create deployment using yaml file
kubectl apply -f deployment.ymldeployment.yml file is having
apiVersion: apps/v1
kind: Deployment
metadata:
name: new-deployment
spec:
replicas: 3
selector:
matchLabels:
name: abc-pod
template:
metadata:
labels:
name: abc-pod
spec:
containers:
- name: abc-container
image: nginx
command:
- sh
- "-c"
- echo Hello Kubernetes! && sleep 3600Here important points are:
apiVersion should follow the way apps/v1 or apps/v
kind is case sensitive
matchlabels.name should be same as metadata.labels.name
You can specify the replica number and that many pods will be created.
When this deployment will be created, a replica set, 3 pods, one deployment will be created.
Case 8: Get all details of the pod
kubectl describe pod <pod_name> -n <namespace>Case 9: Get all pods, replicaset, deployment and services present
kubectl get allCase 10: Editing an existing replicaset
kubectl edit replicaset <replicaset_name>There will be an another post soon dealing with more kubernetes day to day used commands.



Comments