Kubernetes学习笔记(二)

[查看pod里container的logs]

kubectl logs nginx --all-containers=true                  #Return snapshot logs from pod nginx with multi containers

kubectl logs <pod> -n <namespace>

kubectl logs my-pod --previous                              #or "-p", dump pod logs (stdout) for a previous instantiation of a container

kubectl -n <namespace> logs <pod> <container>       #dump the contain logs in the pod

kubectl -n <namespace> logs <pod>  -c <container>

例如: >kubectl logs -p -n kube-system calico-node-6z6ql -c calico-node        #参数p表示previous的container实例

        >kubectl -n kube-system logs csi-cinder-controllerplugin-0 csi-attacher

        >kubectl -n kube-system logs csi-cinder-controllerplugin-0 liveness-probe

 

kubectl logs deploy/my-deployment -n <namespace>                 #dump Pod logs for the Deployment "my-deploement" (single-container case)

kubectl logs deploy/my-deployment -c my-container        #dump container logs in the Pod for a Deployment (multi-container case)

kubectl logs -l app=elasticsearch                                      #用lable选出相关pod的log,适用于1个app

kubectl logs --selector app=yourappname                        #用selector选出相关pod的log

kubectl logs -f deployment/app                                         #用实时流的方式输出相关pod的log

kubectl -n <namespace> logs -f deployment/<app-name>  --all-containers=true --since=10m

#From <https://stackoverflow.com/questions/33069736/how-do-i-get-logs-from-all-pods-of-a-kubernetes-replication-controller?rq=1>

kubectl get events --all-namespaces                       #获取Events信息

kubectl get events --sort-by=.metadata.creationTimestamp     # List Events sorted by timestamp

 

[查看node, pod, container的资源信息]

kubectl describe node <node name>                    # 系统资源capacity,可用的资源情况,以及已经分配的资源情况;包含各pod的cpu,memory等资源requests和limits配置信息

 

kubectl top node <node name>                           # Show metrics for a given node

kubectl get resourcequota                                    # List Resource Quota

kubectl get limitrange                                          # List Limit Range

kubectl set resources deployment nginx -c=nginx --limits=cpu=200m       #设置cpu限制

kubectl set resources deployment nginx -c=nginx --limits=memory=512Mi    #设置memory限制

kubectl top pod -n <namespace> --sort-by=cpu                         #Get pod resource usage, ordered by cpu

kubectl top pod <podname> --containers            #Get resource usage of containers for a given pod

kubectl top pod --all-namespaces --containers=true    #List resource utilization for all containers

kubectl top pod -l name=myLabel           #Show metrics for the pods defined by label name=myLabel

 

kubectl get PodMetrics -n kube-system         #获取含podmetrics的pod

kubectl describe PodMetrics csi-cinder-nodeplugin-94m4k -n kube-system     #获取pod的各个container的metrics信息

 

 

[查看存储信息]

kubectl get storageclass                                           #storageclass信息

kubectl get csinodes                                                #含csi的node

kubectl get volumeattachments                              #PV的挂载信息

kubectl describe volumeattachments <name>       #PV所在node的dev信息

kubectl get volumesnapshots

kubectl get pv

kubectl get pvc

kubectl get pv --sort-by=.spec.capacity.storage      #List PersistentVolumes sorted by capacity

 

[拷贝文件到container]

kubectl cp /tmp/test_dir my-pod:/tmp/bar_dir                     # Copy /tmp/test_dir local directory to /tmp/bar_dir in a remote pod in the current namespace

kubectl cp /tmp/test my-pod:/tmp/bar -c my-container      # Copy /tmp/test local file to /tmp/bar in a remote pod in a specific container

kubectl cp /tmp/test my-namespace/my-pod:/tmp/bar       # Copy /tmp/test local file to /tmp/bar in a remote pod in namespace my-namespace

kubectl cp my-namespace/my-pod:/tmp/test /tmp/bar       # Copy /tmp/test from a remote pod to /tmp/bar locally

posted @ 2022-03-24 13:43  bjtime  阅读(81)  评论(0编辑  收藏  举报