Kubernetes学习笔记(二)
[查看pod里container的logs]
kubectl logs nginx --all-containers=true #Return snapshot logs from pod nginx with multi containers
kubectl logs
kubectl logs my-pod --previous #or "-p", dump pod logs (stdout) for a previous instantiation of a container
kubectl -n
kubectl -n
例如: >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 logs deploy/my-deployment -n
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
kubectl -n
#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
[查看pod里各个容器container的资源信息]
kubectl describe node
kubectl top 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
kubectl top 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
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