美文网首页
k8s常用命令

k8s常用命令

作者: 催化剂 | 来源:发表于2022-07-31 11:20 被阅读0次

    执行当前目录下所有的yml文件

    kubectl apply -f .

    查看kubectl 提供指令的 长名和短名形式

    kubectl api-resources

    kubectl describe 展示资源的详细信息和相关 Event

    kubectl describe pod <podName>

    创建configmap对象-方式一:读取文件的方式,将文件中的内容用于创建configmp

    #用于配置的文件

    cat game.properties

    #configmap from file

    kubectl create configmap game-config --from-file=game.properties

    kubectl create configmap game-env-config --from-env-file=game.properties

    kubectl get configmap -oyaml game-config

    方式二:ConfigMap from literal,创建短小内容,直接赋值的configmap

    kubectl create configmap special-config --from-literal=special.how=very --from-literal=special.type=charm

    #-- from-literal=xx 后跟的即是configmap中的data部分

    Kubectl logs 可查看 pod 的标准输出(stdout, stderr),与 tail 用法类似。

    kubectl logs <-f>

    若日志信息存放在pod内,可通过exec查询

    kubectl exec -it nginx -- tail -f /root/access.log

    #查看所有的命名空间下的node

    kubectl get pod --all-namespaces

    查看所有命名空间

    kubectl get ns

    #查看pod的yaml文档

    kubectl get pod nginx -oyaml

    eg:kubectl get pod calico-node-7kmzk -o yaml -n kube-system

    #删除pod

    kubectl delete pods 容器名(NAME)#删掉1/1的容器

    #重启pod

    kubectl get pod {podname} -n {namespace} -o yaml | kubectl replace --force -f -

    #查看k8s的master控制面板插件

    kubectl get pod -n kube-system

    #启动etcd

    $ kubectl exec -it etcd-cyl sh -n kube-system

    #查看节点

    kubectl get nodes

    #查看节点的yaml文档

    kubectl get node -oyaml

    #编辑pod内容

    kubectl edit po <podName>

    #停止k8s,不会启容器了:

    kubectl drain 10.136.2.73   

    #启动:

    kubectl uncordon 10.136.2.73

    相关文章

      网友评论

          本文标题:k8s常用命令

          本文链接:https://www.haomeiwen.com/subject/sytqwrtx.html