搭建k8s集群-基本命令及使用

基础命令

  • 查看 token 信息:kubeadm token list
  • 创建新的 token:kubeadm token create
  • 查看 sha256 信息:openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
  • 查看节点:kubectl get nodes
  • 删除节点:kubeadm delete nodes k8s-node01
  • 检查组件运行状态:kubectl get cs
  • 检查 Master 状态:kubectl cluster-info
  • 查看服务端支持的API版本:kubectl api-versions
  • 查看模板介绍:kubectl explain pod..
  • 通过资源配置运行容器: kubectl apply -f nginx.yml
  • 通过资源配置删除容器:kubectl delete -f nginx.yml
apiVersion: apps/v1
kind: Deployment
metadata:
    name: nginx-deployment
spec:
    selector:
        matchLabels:
            app: nginx
    replicas: 2
    template:
        metadata:
            labels:
                app: nginx
        spec:
            containers:
            - name: nginx
              image: nginx
              ports:
              - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
    name: nginx-service
spec:
    ports:
      - port: 80
        targetPort: 80
    type: ClusterIP
    selector:
        app: nginx
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
    name: nginx-web
    annotations:
        # 指定 Ingress Controller 的类型
        kubernetes.io/ingress.class: "nginx"
        # 指定我们的 rules 的 path 可以使用正则表达式
        nginx.ingress.kubernetes.io/use-regex: "true"
        # 连接超时时间,默认为 5s
        nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
        # 后端服务器回转数据超时时间,默认为 60s
        nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
        # 后端服务器响应超时时间,默认为 60s
        nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
        # 客户端上传文件,最大大小,默认为 20m
        nginx.ingress.kubernetes.io/proxy-body-size: "10m"
        # URL 重写
        nginx.ingress.kubernetes.io/rewrite-target: /
spec:
    rules:
    - host: k8s.test.com
      http:
        paths:
        - path:
          backend:
            serviceName: nginx-service
            servicePort: 80

  • 查看所有命名空间的pod列表:kubectl get pods --all-namespaces
  • 查看默认命名空间的pod列表:kubectl get pods
  • 查看 pod 详情:kubectl get pod -n kube-system -o wide
  • 查看pod的日志:kubectl logs nginx-deployment-d46f5678b-nvkbg
  • 查看rs列表:kubectl get rs
  • 查看 Deployment 列表:kubectl get deployment
  • 查看 Deployment 详情:kubectl describe deployment nginx-deployment
  • 查看 Service 列表:kubectl get service
  • 查看 Service 详情:kubectl describe service nginx-service
  • 直接修改Service:kubectl edit svc/nginx-service
  • 查看Ingress 详情:kubectl get ingress
  • 查看nginx-Ingress 的Service详情:kubectl get service -n ingress-nginx
  • 查看nginx-Ingress 的Pod详情:kubectl get pods -n ingress-nginx -o wide
  • 扩容:kubectl scale deployment nginx-deployment --replicas 10
  • 更新镜像:kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
  • 回滚:kubectl rollout undo deployment/nginx-deployment

你可能感兴趣的:(搭建k8s集群-基本命令及使用)