Binary deployment K8s cluster advanced use of section 2 kubectl-statement resource management

2. Declarative resource management

2.1 Three methods of managing K8s core resources:

  • Declarative management method-mainly rely on command line CLI tools for management
  • Declarative management method-mainly relies on unified resource allocation (manifest) list for management
  • GUI management method-mainly rely on graphical operation interface (web interface) for management

2.2 Methods of declarative resource management

  • The only entry for kubernetes cluster to manage cluster resources is to call the interface of apiserver through the corresponding method
  • kubectl is the official CLI command line tool, used for apiserver to communicate, organize and convert the commands entered by users on the command line into information that apiserver can recognize, and then realize an effective way to manage various resources of K8S

  • kubectl command list

2.3 Namespace operations

2.3.1 View namespace
kubectl get namespaces
kubectl get ns # 简写
2.3.2 View resources in the namespace
kubectl get all # 查看名称空间内的资源,默认为default名称空间
kubectl get all -n default # 查看default名称空间内的资源
2.3.3 Create Namespace
kubectl create namespace app
2.3.4 Delete namespace
kubectl delete ns app

2.4 deployment operation

2.4.1 Create deployment
kubectl create deployment ningx-test --image=harbor.od.com/public/nginx:1.7.9 -n kube-public  # 创建一个控制器
kubectl expose deployment nginx-dp --port=80 -nkube-public # 暴露80端口
2.4.2 View deployment
kubectl get deploy -o wide -n kube-public
kubectl descibe deployment nginx-test -n kube-publice # 查看详细信息
kubectl scale deployment nginx-dp --replicas=4 -n kube-public # 扩容4个pod
2.4.3 Delete deployment
kubectl delete deploy ningx-test -n kube-public     

2.5 node operation

2.5.1 View node
kubectl get nodes
2.5.2 Change label to node
kubectl label node hdss7-22.host.com node-role.kubernetes.io/master= 

2.5.3 View cluster node network cards

ifconfig cni |head -2

2.6 Pod operation

2.6.2 Enter pod
kubectl exec -ti nginx-dp-7f74c75ff9-9dpr8 /bin/bash -n kube-public
2.6.2 Delete pod
kubectl delete pod my-nginx-cjql6
2.6.3 View pod
kubectl get pods -o wide -n kube-public # 查看内网IP
kubectl get node -n kube-public --show-labels # 查看标签 
kubectl describe pod 查看容器名 # 查看容器详细信息
kubectl edit pod 查看容器名 # 查看容器详细信息
kubectl get pod 查看容器名 -o yaml # 查看容器详细信息
kubectl logs 容器名 # 查看容器日志

2.7 svc operation

kubectl get svc -o wide -n kube-public # 查看svc集群IP
kubectl describe svc nginx-dp -n kube-public # 查看详细信息

2.8 View Help Document

kubectl explain namespace
kubectl explain service.kind
kubectl explain service.metadata
kubectl explain pod.spec.containers

Guess you like

Origin blog.51cto.com/yht1990/2539864