第九章 kubectl 操作示例

创建资源对象

  1. 根据yaml 配置文件一次性创建service、rc

    kubectl create -f my-service.yaml -f my-rc.yaml

  2. 查看资源对象

    • 查看所有pod 列表

        kubectl get pod -n <namespace>
      
    • 查看RC和service 列表

        kubectl get rc,svc
      
  3. 描述资源对象

    • 显示Node的详细信息

        kubectl describe node <node-name>
      
    • 显示Pod的详细信息

        kubectl describe pod <pod-name>
      
  4. 删除资源对象

    • 基于pod.yaml 定义的名称删除pod

        kubectl delete -f pod.yaml
      
    • 删除所有包含某个label的pod 和service

        kubectl delete pod,svc -l name=<label-name>
      
    • 删除所有Pod

        kubectl delete pod --all
      
      复制
  5. 执行容器的命令

    • 执行pod 的date 命令

        kubectl exec <pod-name> -- date
      
    • 通过bash 获得pod中某个容器的TTY,相当于登陆容器

        kubectl exec -it <pod-name> -c <container-name> -- bash
      
  6. 查看容器的日志

         kubectl logs <pod-name> 

关注微信公众号,获取更多信息

猜你喜欢

转载自blog.csdn.net/qq_37950254/article/details/89444004