当前位置:网站首页>[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
2022-07-05 08:07:00 【It's a bubble】
This article has been featured 《 Learn from scratch k8s》 Included
kubectl Detailed explanation
summary
kubectl yes Kubernetes Command line tools for clustering , adopt kubectl Be able to manage the cluster itself , And can install and deploy container applications on the cluster .
Command format
The command format is as follows
kubectl [command] [type] [name] [flags]
Parameters
command: Specifies the action to be performed on the resource , for example create、get、describe、delete
type: Specify the resource type , Resource types are case sensitive , Developers can use the singular number , The plural , Abbreviated form specifies .
name: Specify the name of the resource , Names are also case sensitive , If you omit the name , All resources will be displayed .
flags: Specify additional optional parameters , For example, you can use -s perhaps -server Parameter assignment Kubernetes API server The address and port of
for example :
kubectl get pod pod1
kubectl get pods pod1
kubectl get po pod1
kubectl get pods
Common command
kubectl help For more information
adopt help command , Can get help information
# obtain kubectl The order of
kubectl --help
# Get the introduction and use of a command
kubectl get --help
# View the current status
kubectl get cs
# View all pod
kubectl get pod
# View a certain pod
kubectl get pod pod_name
# View a certain pod, With yaml Format display results
kubectl get pod pod_name -o yaml
Basic commands
Common basic commands
command | Introduce |
---|---|
create | Create resources by filename or standard input |
expose | Expose a resource as a new Service |
run | Run a specified image in the cluster |
set | Set specific functions on objects |
get | Show one or more resources |
explain | Show document references |
edit | Use the default editor to edit a resource |
delete | By file name , The standard input , Resource name or tag to delete the resource |
apply | Apply configuration to resources by filename or standard input |
patch | Patch modification 、 Update resources |
replace | Replace a resource with a filename or standard input |
convert | Different API Convert configuration files between versions |
label | Update the label on the resource |
annotate | Update comments on resources |
completion | Used to implement kubectl The tool automatically completes |
api-versions | Print supported API edition |
config | modify kubeconfig file ( Used to access the API, For example, configure authentication information ) |
help | All command help |
plugin | Run a command line plug-in |
version | Print client and service version information |
Deployment command
command | Introduce |
---|---|
rollout | Manage the release of resources |
rolling-update | Scroll through the updates for a given replication controller |
scale | Expand or shrink Pod Number ,Deployment、ReplicaSet、RC or Job |
autoscale | Create an automatic selection to expand or shrink and set Pod Number |
Cluster management commands
command | Introduce |
---|---|
certificate | Modify certificate resources |
cluster-info | Display cluster information |
top | Show resources (CPU/M) |
cordon | The tag node is not schedulable |
uncordon | Marker nodes can be scheduled |
drain | Applications on eviction nodes , Prepare for offline maintenance |
taint | Modify node taint Mark |
Fault and debug commands
command | Introduce |
---|---|
describe | Show details of a specific resource or resource group |
logs | In a Pod Print a container log , If Pod There is only one container , The container name is optional |
attach | Attach to a running container |
exec | Execute command to container |
port-forward | Forward one or more |
proxy | Run one proxy To Kubernetes API Server |
cp | Copy files or directories into containers |
auth | Check authorization |
Currently commonly used commands
# Create a nginx Mirror image
kubectl create deployment nginx --image=nginx
# External exposure port
kubectl expose deployment nginx --port=80 --type=NodePort
# See the resources
kubectl get pod
# View details ip, Port, etc .
kubectl get svc
demonstration
Create a namespace
[[email protected] ~]# kubectl create namespace paopao
namespace/paopao created
obtain namespace
[[email protected] ~]# kubectl get ns
NAME STATUS AGE
default Active 7d23h
kube-node-lease Active 7d23h
kube-public Active 7d23h
kube-system Active 7d23h
paopao Active 22s
Here it is namespace Create and run a nginx Of Pod
[[email protected] ~]# kubectl run pod --image=nginx:latest -n paopao
pod/pod created
See the newly created pod
[[email protected] ~]# kubectl get pod -n paopao
NAME READY STATUS RESTARTS AGE
pod 1/1 Running 0 3m14s
Delete specified namespace
[[email protected] ~]# kubectl delete ns dev
namespace "dev" deleted
establish / Update resources Configure with declarative objects kubectl apply -f XXX.yaml
Delete resources Use command object configuration kubectl delete -f XXX.yaml
Query resources Use imperative object management kubectl get(describe) Resource name
Resource Management
Imperative object management : Directly use commands to operate kubernetes resources , Direct action object , Suitable for testing , Relatively simple , The disadvantage is that you can only manipulate active objects , Unable to audit trail .
kubectl run nginx-pod --image=nginx --port=80
Imperative object configuration : Operate through command configuration and configuration file kubernetes resources , Direct operation of documents , Suitable for development , Can audit and track , But if the project is too big , There will be many configuration files , Operation trouble .
kubectl create -f nginx-pod.yaml
kubectl patch -f nginx-pod.yaml
Declarative object configuration : adopt apply Commands and configuration files to operate kubernetes resources , Direct operation directory , Suitable for development , Support directory operation , But it's not easy to debug .
kubectl apply -f nginx-pod.yaml
The resource type
kubernetes All the content in is abstracted as resources , You can check it with the following command :
kubectl api-resources
At the end
It's not easy to create , If you think the content will help you , Please pay attention to the third company and support me ! If there is an error , Please point out... In the comment area , I'll change it in time !
Series currently being updated : Learn from scratch k8s, Learn from scratch zabbix
Thank you for watching , The article is mixed with personal understanding , If there is any error, please contact me to point out ~
边栏推荐
- Gradle复合构建
- 导电滑环磨损快的原因
- The printer encountered an abnormal configuration problem 0x8007007e (win10)
- Network port usage
- Shell script basic syntax
- Fundamentals of C language
- Improve lighting C program
- C WinForm [display real-time time in the status bar] - practical exercise 1
- Step motor generates S-curve upper computer
- Nb-iot technical summary
猜你喜欢
Shape template matching based on Halcon learning [VII] reuse_ model. Hdev routine
Network communication model -- Network OSI tcp/ip layering
Hardware and software solution of FPGA key chattering elimination
Development tools -- gcc compiler usage
C language # and #
Factors affecting the quality of slip rings in production
导电滑环磨损快的原因
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
After installing the new version of keil5 or upgrading the JLINK firmware, you will always be prompted about the firmware update
Screen record of the opening ceremony of the Beijing winter olympics 2
随机推荐
Ads learning record (lna_atf54143)
Stablq of linked list
C # joint configuration with Halcon
Count and sort the occurrence times of specific fields through SQL statements
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
[trio basic tutorial 18 from introduction to proficiency] trio motion controller UDP fast exchange data communication
Semiconductor devices (I) PN junction
Semiconductor devices (III) FET
Hardware and software solution of FPGA key chattering elimination
How to define guid in AMI code
Network communication process
C WinForm [change the position of the form after running] - Practical Exercise 4
Altium designer 19.1.18 - clear information generated by measuring distance
找不到实时聊天软件?给你推荐电商企业都在用的!
LED display equipment records of the opening ceremony of the Beijing Winter Olympics
OLED 0.96 inch test
Halcon's practice based on shape template matching [1]
Compilation warning solution sorting in Quartus II
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
Naming rules for FreeRTOS