Create new pod based on nginx version 1.10.0 image
$ kubectl run nginx --image=nginx:1.10.0
List available pods
$ kubectl get pods
Create service to allow connecting to the existing pod listen to port 80
$ kubectl expose deployments nginx --port 80 --type loadBalancer
List available services
$ kubectl get services
Create pods based on ymal file
$ kubectl create -f pods/monolith.yaml
Working with one POD
List available pods to get pod name
$ kubectl get pods
Get Pod details
$ kubectl describe pods <<Pod Name>>
Forward traffic from a given host port to pod port
$ kubectl port-forward <<Pod Name>> <<Host Port >> : <<Pod Port >>
View Pod Logs
$ kubectl logs <<Pod Name>>
View Pod Logs stream in realtime
$ kubectl logs -f <<Pod Name>>
Login to shell inside a Pod
$ kubectl exec <<Pod Name >> --stdin --tty -c <<Pod Name >> /bin/sh
To logout from Pod SSH
$ exit
==============================================
Working with group of PODs (using Services)
Sample service yaml configuration file
Notes: we select the pods that will affected by this service using "selector" section
Create Service based on yaml file
$ kubectl create -f services/monolith.yaml
Select Pods based on selection criteria (pods that has some labels)
$ kubectl get pods -l "app=monolith, secure=enabled"
Add label to exist pod
$ kubectl label pods << Pod Name >> "Lable1 = Value1"
References
List of available commands
https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands
how to do individual tasks step by step
https://kubernetes.io/docs/tasks/
No comments:
Post a Comment