kubectl

查看集群信息

 ~]# kubectl cluster-info
Kubernetes control plane is running at https://10.4.7.250:6443
CoreDNS is running at https://10.4.7.250:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://10.4.7.250:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

查看api 组

kubectl api-versions

查看k8s中的资源类型

kubectl api-resources

创建名称空间

kubectl create ns  my-namespace --dry-run=client -o yaml

创建pod

kubectl run nginx --image=nginx --namespace=<名字空间名称>

查看pod

kubectl get pods 
kubectl run test-kubectl  --image=alpine --dry-run=client -- sleep 100 --namespace=<名字空间名称> --dry-run=client -oyaml

创建secret

kubectl create secret docker-registry <name> --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL

可以查看到svc 后端有多少个真实服务器

kubectl get ep -A

回滚

kubectl rollout status deployment/nginx-deployment

设置默认的名称空间

kubectl config set-context --current --namespace=<名字空间名称>

查看配置文件

kubectl config view | grep namespace:

查询资源使用率,1.11之前使用heapster。之后使用metrics server

kubectl top node
kubectl top pod -A 

在pod 中查看当前pod所属名称空间

# 容器内执行
cat /var/run/secrets/kubernetes.io/serviceaccount/namespace

污点:node上做污点

#给prometheus单独配置一个运算节点
kubectl taint node hdss7-21.host.com quedian=buxijiao:NoSchedule
kubectl taint node hdss7-21.host.com quedian=:NoSchedule
kubectl taint node hdss7-21.host.com quedian=buxijiao-
#NoExecute  通过排干节点上的pod ===》kubectl taint node hdss7-21.host.com key=:NoExecute
kubectl taint node hdss7-21.host.com key=broken:NoExecute
kubectl taint node hdss7-21.host.com key=:NoExecute
kubectl taint node hdss7-21.host.com key-

kubectl run

  1. --image

    kubectl run test --image=busybox --dry-run=client -oyaml
    
  2. --labels

    kubectl run test --image=busybox --labels "app=web,env=uat" --dry-run=client -oyaml
    
  3. --annotations

    kubectl run test --image=busybox --labels "app=web,env=uat" --annotations "describe=this is a test pod create by kubectl" --dry-run=client -oyaml
    
  4. --port

    kubectl run test --image=busybox --labels "app=web,env=uat" --annotations "describe=this is a test pod create by kubectl" --port=80 --dry-run=client -oyaml
    
  5. --env

    kubectl run test --image=busybox --env "port=6379" --env "host=127.0.0.1" --dry-run=client -oyaml
    
  6. --restart

    kubectl run test --image=busybox --env "port=6379" --env "host=127.0.0.1" --restart=OnFailure --dry-run=client -oyaml
    
  7. --expose

    kubectl run test --image=busybox --env "port=6379" --env "host=127.0.0.1" --restart=OnFailure --port=6379 --expose --dry-run=client -oyaml 
    
  8. --image-pull-policy

     kubectl run test --image=busybox --env "port=6379" --env "host=127.0.0.1" --restart=OnFailure --port=80 --expose --image-pull-policy=Never --dry-run=client -oyaml
    
  9. --privileged

     kubectl run test --image=busybox --env "port=6379" --env "host=127.0.0.1" --restart=OnFailure --port=80 --expose --image-pull-policy=Never --dry-run=client -oyaml --privileged
    
posted @ 2022-05-11 23:54  mingtian是吧  阅读(44)  评论(0编辑  收藏  举报