当前位置:网站首页>[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 ~
边栏推荐
- Shell脚本基本语法
- Ads learning record (lna_atf54143)
- Use indent to format code
- Soem EtherCAT source code analysis attachment 1 (establishment of communication operation environment)
- Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
- Random function usage notes
- Basic embedded concepts
- Global and Chinese markets for recycled boilers 2022-2028: Research Report on technology, participants, trends, market size and share
- Circleq of linked list
- C language # and #
猜你喜欢
![[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement](/img/54/78e4e10724b2762274b06debb10877.jpg)
[trio basic tutorial 16 from introduction to proficiency] UDP communication test supplement

研究發現,跨境電商客服系統都有這五點功能!

A simple method to prove 1/t Fourier transform

Shell脚本基本语法

C language enhancement -- pointer

How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?

DokuWiki deployment notes

Management and use of DokuWiki

VESC Benjamin test motor parameters
![[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc](/img/9e/2524cbb9b90135c54669ba8d5338b7.jpg)
[trio basic from introduction to mastery tutorial 20] trio calculates the arc center and radius through three points of spatial arc
随机推荐
My-basic application 1: introduction to my-basic parser
Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
L'étude a révélé que le système de service à la clientèle du commerce électronique transfrontalier a ces cinq fonctions!
Shape template matching based on Halcon learning [9] PM_ multiple_ dxf_ models. Hdev routine -- [read and write XLD from DXF file]
C WinForm [change the position of the form after running] - Practical Exercise 4
2021-10-28
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
导电滑环磨损快的原因
Naming rules for FreeRTOS
IC software learning
Management and use of DokuWiki
[professional literacy] core conferences and periodicals in the field of integrated circuits
Explain task scheduling based on Cortex-M3 in detail (Part 2)
The printer encountered an abnormal configuration problem 0x8007007e (win10)
Halcon's practice based on shape template matching [2]
PMSM dead time compensation
研究發現,跨境電商客服系統都有這五點功能!
MySQL blind note common functions
C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
Bootloader implementation of PIC MCU