You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kubectl get pods # default namespace
kubectl get pods -n kube-system #list kube-system namespace pods.
kubectl get pods --all-namespaces
kubectl get pods -A # all-namespace
more info about pods
kubectl get pods -A # all-namespace
kubectl get pods -A -o wide # all-namespace with more detailed
kubectl get pods -A -o yaml
kubectl get pods -A -o json
kubectl get pods -A -o go-template
kubectl get pods -A -o json | jq -r ".items[].spec.containers[].name" #jq parser query
kubectl delete -f podlabel.yaml #all related objects deleted with declerative way
watch pods always
kubectl get pods -w
run multiple container on 1 pod, -c containerName
kubectl exec -it multicontainer -c webcontainer -- /bin/sh # -c ile containername, if more than one container
kubectl exec -it multicontainer -c sidecarcontainer -- /bin/sh
kubectl logs -f multicontainer -c sidecarcontainer
port-forward to pod
kubectl port-forward pod/multicontainer 80:80 ## host:container port, if command is not run, port is not opened
kubectl port-forward pod/multicontainer 8080:80 # when browsing 127.0.0.1:8080, host:8080 goes to pod:80 and directs traffic.
kubectl port-forward <pod-name> <locahost-port>:<pod-port>
kubectl port-forward deployment/mydeployment 5000 6000 # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the deployment
kubectl port-forward service/myservice 5000 6000 # Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in a pod selected by the service
kubectl port-forward --address localhost,10.19.21.23 pod/mypod 8888:5000 # Listen on port 8888 on localhost and selected IP, forwarding to 5000 in the pod
kubectl port-forward pod/mypod :5000 # Listen on a random port locally, forwarding to 5000 in the pod
kubectl port-forward --address 0.0.0.0 pod/mypod 8888:5000 # Listen on port 8888 on all addresses, forwarding to 5000 in the pod
label ve selector
kubectl get pods -l "app" --show-labels #with -l, search label
kubectl get pods -l "app=firstapp" --show-labels
kubectl get pods -l "app=firstapp,tier=frontend" --show-labels
kubectl get pods -l "app in (firstapp)" --show-labels
kubectl get pods -l "!app" --show-labels #list not app key
kubectl get pods -l "app notin (firstapp)" --show-labels #inverse
kubectl get pods -l "app in (firstapp,secondapp)" --show-labels #or
kubectl get pods -l "app=firstapp,app=secondapp)" --show-labels #and
kubectl apply -f deployrolling.yaml --record
kubectl edit deployment rolldeployment --record
kubectl set image deployment rolldeployment nginx=httpd:alpine --record=true
kubectl rollout history deployment rolldeployment # show record history
kubectl rollout history deployment rolldeployment --revision=2 # show 2.revision history
kubectl rollout undo deployment rolldeployment --to-revision=1 # roll to the first revision
live rollout commands logs on different terminal
kubectl apply -f deployrolling.yaml
on another terminal: kubectl rollout status deployment rolldeployment -w
kubectl rollout pause deployment rolldeployment # pause the current deployment rollout/update
kubectl rollout resume deployment rolldeployment # resume the current deployment rollout/update
kubectl apply -f serviceClusterIP.yaml
kubectl get service -o wide
service with command
kubectl expose deployment backend --type=ClusterIP --name=backend #clusterIP type service creation
kubectl get service
kubectl expose deployment frontend --type=NodePort --name=frontend #ndePort type service creation
kubectl get service
service-endpoints
kubectl get endpoints # same endpoints created with services
kubectl describe endpoints frontend # show ip adresses
kubectl delete pods frontend-xx-xx # when pod deleted, ip also deleted
kubectl scale deployment frontend --replicas=5 # new ip added
kubectl scale deployment frontend --replicas=2
ephemeral volume (temporary volume): it can be reachable from more than 1 container in the pod. When pod is deleted, volume is also deleted like cache.
2 types of ephmeral volume:
1.emptydir (create empty directory on the node, this volume is mounted on the container)
2.hostpath: worker node (worker PC) with file path, more than one file or directory can be connected