管理类
kubectl 工具用法
kubectl 子命令 资源对象类型 资源对象名称 子命令可选参数
查看版本
kubectl version
查看集群node
kubectl get nodes
查看命名空间
kubectl get namespace
查看命名空间下的对象,不加参数--namespace 默认default
kubectl get pod
kubectl get pod --namespace kube-system
查看pod , node节点详细信息
kubectl describe node 192.168.0.133
kubectl describe pod nginx-a12s
kubectl describe pod nginx-a12s -n kube-system
kubectl get svc #(kubectl get services)
查看pod详情
kubectl describe pod podname
kubectl get pods --all-namespaces
同时使用多个yaml文件创建
kubectl create -f a.yaml -f b.yaml -f c.yaml
创建 根据目录下所有yaml yml json文件创建
kubectl create -f 路径
删除 基于yaml
kubectl delete -f a.yaml
删除 所有包含某个label的pod和service
kubectl delete pods,services -l name=*
删除所有pod
kubectl delete pods --all
指定pod中的某个容器执行date命令
kubectl exec podename date -c ** date
通过bash获得pod中某个容器的tty,相当于登录容器
kubectl exec -ti podname -c * /bin/bash
kubectl exec -ti nginx-wbfm4 -- /bin/bash
查看容器输出到stdout的日志
kubectl logs *
跟踪查看容器的日志 相当于tail -f
kubectl logs -f podname -c *
创建或更新资源对象(不存在就创建,存在就更新)
kubectl apply -f app.yaml
pod和本地间复制文件 赋值pod的etc到本地data
kubectl cp nginx:/etc /data
kubectl输出格式
json格式输出
kubectl get pod -o=json
根据自定义列输出,逗号隔离
kubectl get pod -o=custom-columns=***
从文件获取列名输出
kubectl get pod -o=custom-columns-flie=***
输出jsonpath表达上定义的字段信息
kubectl * -o=jsonpath=*
输出jsonpath表达上定义的字段信息,来源于文件
kubectl * -o=jsonpath-file=*
仅输出资源对象名称
kubectl * -o=name
输出额外信息
kubectl * -o=wide
yaml格式显示结果
kubectl * -o=yaml
kubectl get pod -o=custom-columns=NAME:metadata.name,RSRC:.metadata.resourceVersion
查看etcd是否正确启动
etcdctl cluster-health
......