Kubernetes is an open-source container orchestration system for automating software deployment, scaling, and management.
Fetching version
kubectl version
Fetching details of types (Pods, Services, Deployments, ReplicaSets)
kubectl get <type>
Fetching details of all objects
kubectl get all
fetching pods with more details(including ip addresses)
kubectl get pods -o wide
Running a pod
kubectl run <name> --image=<image_name>
Creating an object using a yaml file
kubectl create -f <file_name>
Update or Apply Changes
kubectl apply -f <file_name>
# (or)
kubectl replace -f <file_name>
Fetching details of particular object
kubectl describe <type> <name>
Scaling the objects
kubectl scale --replicas=6 <type> <name>
Deleting
kubectl delete <type> <name>
Updating the properties in YAML format
kubectl edit <type> <name>
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:latest
ports:
- containerPort: 80
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: example-replicaset
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:latest
ports:
- containerPort: 80
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:latest
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Types: ClusterIP, NodePort, LoadBalancer
Explained about Services in detail Here