当前位置:网站首页>[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 ~
边栏推荐
- Ads usage skills
- [tutorial 15 of trio basic from introduction to proficiency] trio free serial communication
- WiFi wpa_ Detailed description of supplicant hostpad interface
- My-basic application 1: introduction to my-basic parser
- Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
- About yolov3, conduct map test directly
- How to migrate the device data accessed by the RTSP of the easycvr platform to easynvr?
- C, Numerical Recipes in C, solution of linear algebraic equations, LU decomposition source program
- UEFI development learning 2 - running ovmf in QEMU
- Count and sort the occurrence times of specific fields through SQL statements
猜你喜欢
如何将EasyCVR平台RTSP接入的设备数据迁移到EasyNVR中?
Correlation based template matching based on Halcon learning [II] find_ ncc_ model_ defocused_ precision. hdev
Why is 1900 not a leap year
Management and use of DokuWiki
Measurement fitting based on Halcon learning [II] meaure_ pin. Hdev routine
The firmware of the connected j-link does not support the following memory access
Programming knowledge -- basis of C language
PMSM dead time compensation
Reasons for rapid wear of conductive slip rings
C WinForm [help interface - send email] - practice five
随机推荐
The firmware of the connected j-link does not support the following memory access
Circleq of linked list
C # joint configuration with Halcon
DokuWiki deployment notes
Management and use of DokuWiki (supplementary)
Random function usage notes
UEFI development learning 5 - simple use of protocol
Consul installation
Programming knowledge -- assembly knowledge
Development tools -- gcc compiler usage
PMSM dead time compensation
VESC Benjamin test motor parameters
Measurement fitting based on Halcon learning [III] PM_ measure_ board. Hdev routine
Create inf module in AMI code
Hardware and software solution of FPGA key chattering elimination
Sql Server的存储过程详解
Semiconductor devices (I) PN junction
Arduino uses nrf24l01+ communication
Sql Server的存儲過程詳解
生产中影响滑环质量的因素