In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Brief introduction of Kubectl
Before learning how to use kubectl more effectively, you should have a basic understanding of what it is and how it works.
From the user's point of view:
Kubectl is the cockpit that controls Kubernetes. It allows you to perform all possible Kubernetes operations.
From a technical standpoint:
Kubectl is the client of Kubernetes API, through which we have full control of Kubernetes, which means that each Kubernetes operation is exposed as an API port and can be performed through an HTTP request to this endpoint.
Command Daquan (as far as I know) query command
View all pod
Kubectl get pods
Dynamic monitoring to view all pod
Kubectl get pods-w
View all deploymen
Kubectl get deployment
View all service services
Kubectl get service
View associated backend nodes
Kubectl get endpoints
View the log of the relevant POD
Kubectl get logs NAME
Pod copy quantity adjustment
Kubectl scale [--current-replicas=replicas]-- replicas=replicas NAME
Among them
Current number of copies of "--current-replicas"
Number of copies of "--replicas"
The life cycle of the project
Create-- "publish--" update-- "rollback--" delete
Create
Kubect run NAME-- image=image [--port=port] [--replicas=replicas] [--command]
"--image" specifies the image
"--replicas" specifies the number of copies
"--port" specifies the intercom port
Example: kubectl run nginx-- image=nginx:latest-- replicas=3
Use the latest version of nginx as a mirror to create a pods with three copies
Publish
Kubectl expose (- f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP | UDP | SCTP] [--target-port=number-or-name] [--name=name] [--external-ip=external-ip-of-service] [--type=type]
"- f FILENAME" specifies the YAML file name
"TYPE NAME" specifies the deploymen name
"--type" specifies the service type (default is cluster address-clusterip)
Port for internal communication of "--port=80"
"--target-port=80" exposed to external ports
Example: kubectl expose deploy/nginx-- port=80-- target-port=80-- name=nginx-svc-- type=NodePort
Publish nginx as internal port 80, exposed port 80, specified name as nginx-svc, type as node.
Update
New version of kubectl set image deploy/NAME NAME=
Example: kubectl set image deploy/nginx nginx=nginx:1.14
Change nginx version to nginx1.14
Roll back
Kubectl rollout [commands]
Common command:
History displays rollout history
The resource provided by the pause tag is aborted
Resume continues a stopped resource
Status displays the status of rollout
Undo undoes the last rollout
Example: kubectl rollout undo deploy/nginx
Delete
Kubectl delete ([- f FILENAME] | TYPE [(NAME |-l label |-- all)]) [options]
Example:
Kubectl delete svc/nginx-svc
Kubectl delete deploy/nginx
In addition, there are a number of orders.
View resource object abbreviations
Kubectl api-resources
View specific resource details
Kubectl describe (- f FILENAME | TYPE [NAME_PREFIX |-l label] | TYPE/NAME) [options]
Example:
Kubectl describe pod/nginx-7697996758-9d6tf
Kubectl describe svc/nginx
Edit resource details
Kubectl edit (- f FILENAME | TYPE [NAME_PREFIX |-l label] | TYPE/NAME) [options]
Example:
Kubectl edit deploy/NAME
Enter the corresponding pod *
Kubectl exec POD [- c CONTAINER]-- COMMAND [args...] [options]
Example: kubectl exec-it nginx-7697996758-9d6tf bash
View the generated YAML format file
Kubectl run nginx-deployment-image=nginx-port=80-replicas=3-dry-run-o yaml
View the generated JSON format file
Kubectl run nginx-deployment-image=nginx-port=80-replicas=3-dry-run-o json
Generate YAML and JSON file export
Kubectl run nginx-deployment-image=nginx-port=80-replicas=3-dry-run-o json (yaml) > test.json (yaml)
Export existing resources
Kubectl get svc/nginx-svc-- export-o yaml > nginx-svc.yaml
Test the correctness of the command and do not execute it (similar to sh-n in shell script)
Kubectl run nginx-image=nginx-port=80-replicas=2-dry-run
Similarities and differences between create and apply
Create from a YAML file
Kubectl create-f FILENAME [options]
Example: kubectl create-f nginx.yaml
Upgrade deployment from a YAML file
Kubectl apply-f FILENAME
Similarities and differences if the deployment value in the yaml file is deployment, then both of the above commands can create a deployment and generate a corresponding number of podcreate commands: delete all existing things first and generate new ones based on the yaml file. So the configuration in the yaml file must be a complete apply command: upgrade the existing one according to what is listed in the configuration file. So the contents of the yaml file can only write the attributes that need to be upgraded.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.