On the road again

The article describes basic commands for creating pods and working with them

Example pod.yml with pod description:
apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  labels:
    zone: prod
    version: v1
spec:
  containers:
  - name: hello-ctr
    image: <some_docker_image>
    ports:
    - containerPort: 8080
 
Install:
sudo kubectl create -f pod.yml
 
View information about newly created pod:
kubectl get pods -o json hello-pod
 
List all pods:
kubectl get pods
kubectl get pods --show-labels
 
Describe pod:
kubectl describe pods hello-pod
 
Add/change/delete  a label to pod:
kubectl label pod echoserver2 mylabel2=value2
kubectl label pod echoserver2 mylabel1=value2 --overwrite
kubectl label pod echoserver2 mylabel2-
 
Add/change/delete an annotation to a pod:
kubectl annotate pod echoserver description="A simple echoserver application"
kubectl annotate pod echoserver --overwrite description="A simple echoserver application v1.4"
kubectl annotate pod echoserver description-
 
Execute command on first container in the pod:
kubectl exec hello-pod ps aux
 
Login to the shell on first node in the pod:
kubectl exec -it hello-pod sh
If you are running multi-container Pods, you will need to pass the kubectl exec command the --container flag and give it the name of the container in the Pod that you want to create the exec session with. If you do not specify this flag, the command will execute against the first container in the Pod. You can see the ordering and names of containers in a Pod with the kubectl describe pods command.
Добавить комментарий