Kubernetes uses Kube-Apiserver as the gateway to the entire cluster management. Apiserver is the primary management node of the entire cluster. Users use Apiserver to configure and organize clusters, and nodes in clusters interact with ETCD storage through Apiserver. Apiserver implements a set of RESTfull interfaces. Users can directly interact with the Apiserver using the API. In addition, the official also provides a client kubectl package with the tool set, used to directly through Kubectl command line with the cluster interaction project part of the service with K8S deployment, research environment department built cluster, version is lower and the machine in the cluster often fail, How to configure Kubectl in Windows and work in common operation node and POD command

Configure Kubectl on Windows

download

Dl.k8s. IO /release/v1…. Website links: kubernetes. IO/docs/tasks /…

Configuring environment Variables

[This computer] → [Properties] → [Advanced System Configuration]

The path to addD:\xxx\tools\kube, this directory is the directory where kubectl.exe is stored, we can directly run kubectl CMD to try the effect



At this point our Kubectl is fairly installed

Configuration kubeconfig

Kubectl by default looks for a file named config from the $HOME/. Kube directory. You can also set the environment variable KUBECONFIG or specify other KUBECONFIG files by setting KUBECONFIG. Kube config file. We can use kubectl to access the k8S cluster directly. Also, if we want to use some grep command, You can use Git Bash client to do this:

kubectl get pods -n 375-xxx-pre NAME READY STATUS RESTARTS AGE xxx-pre-xxx-85f4ff7998-7bz6s 0/1 CrashLoopBackOff 345 36d  xxx-pre-xxx-696d949fbf-8qccb 1/1 Running 223 49d xxx-pre-xxx-xxx-v4-6cf49766d6-zc9b2 1/1 Running 1 6h xxx-pre-xxx-xxx-v4-5bd5b69898-wglpz 1/1 Running 0 11h xxx-pre-xxx-xxx-v4-7bb478c5fc-xlhxk 1/1 Running 0 6h edu-asyn-xxx-55bcbdffc5-pf9l8 1/1 Running 0 7d nginx-ingress-controller-5b548fbf68-4jjn9 1/1 Running 0 1y term-xxx-c7795745c-vljdf 1/1 Running 0 330d texlive-python-api-7b69cd5fd7-zhfcs 1/1 Running 0 14d web-open-695b4bf966-j9k7g 1/1 Running 0 329dCopy the code

Common kubectl command

The node operating

# Query node information
kubectl get nodes

# query more information about the node
kubectl get nodes -o wide

# pause node
kubectl cordon node_xxx

# restore node
kubectl uncordon node_xxx

# Gently remove nodes (use caution)
kubectl drain node_xxx

# Forcible delete (use caution)
kubectl delete node node_xxx
Copy the code

Pod operation

Create pod with the number pod_xxx.yaml
kubectl create -f pod_xxx.yaml

Query all pod information
kubectl get pods

# More info
kubectl get pods -o wide

Query pods details for a single namespace
kubectl get pods -n namespace_xxx -o wide

# Check for a single POD
kubectl get pod pod_xxx -n namespace_xxx -o wide

# Trace pod logs
kubectl logs -f pod_xxx -n namespace_xxx

Enter a single pod
kubectl exec -it pod_xxx -n namespace_xxx bash

View individual POD status and lifecycle
kubectl describe pod pod_xxx -n namespace_xxx

Display complete Pod information in JSON format
kubectl get pod pod_xxx  -n namespace_xxx --output json

YAML displays complete Pod information
kubectl get pod pod_xxx  -n namespace_xxx --output yaml

# update pod
kubectl replace -f pod_xxx.yaml

# create a pod. Some properties of the pod cannot be modified, such as the container image
kubectl replace --force -f pod_xxx.yaml

Delete a single pod
kubectl delete pod pod_xxx

# delete all pods O(∩_∩)O
kubectl delete pod --all
Copy the code

other

# check the number of copies, default is one
kubectl get deployments

# set the number of replicas to 3
kubectl scale deployments/xxx --replicas=3

# Resize to one
kubectl scale deployments/xxx --replicas=1

#...
Copy the code

Refer to the link

About kubectl related with blogger summary is very good, if you want to see more please click: Kubernetes kubectl commonly used command: blog.csdn.net/xingwangc20…