In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the basic knowledge points of kubectl". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the basic knowledge points of kubectl"?
Preface
Readers who know a little about Kubernetes should know the saying of declarative API. Kubectl is a client of this kind of API, so the main function of kubectl is to manipulate objects.
action
In kubectl, it is called command, that is, command. Use kubectl-- help to see a list of available commands:
$kubectl-help
Kubectl controls the Kubernetes cluster manager.
Find more information at: https://kubernetes.io/docs/reference/kubectl/overview/
Basic Commands (Beginner):
Create Create a resource from a file or from stdin.
...
Run runs a specified image in the cluster
...
Basic Commands (Intermediate):
Explain views the documentation of the resource
Get displays one or more resources
...
Deploy Commands:
Rollout Manage the rollout of a resource
...
You can see that kubectl's command line help is very good, with not only functional descriptions, categories, but also difficulty marks, and even some Chinese instructions. Each command of kubectl can be used-- help to view further help instructions.
Here is a list of many available commands, according to the operation ability, the mainstream commands can be divided into four kinds of CRUD.
C
The new command is used to create objects in the cluster. The most commonly used new commands are create and run. Create can create multiple objects, while run is mainly used to create Pod. Both commands need to use parameters to express the field content of the object to be created on the command line, which is very rough and limited, and has obvious imperative API flavor, which is seldom used in my daily work.
But this command often has an ingenious use,-- dry-run=client (in the old version is-- dry-run), which can test the output of the command without actually producing it, plus-o yaml, to help output the YAML document.
R
Get is the most commonly used query instruction to get a list of objects and basic information, while describe is used to get the details of an object. Another common read instruction is the log view instruction commonly used by Debug: kubectl logs.
U
The most important update command can be said to be apply,edit, and patch, label, annotation, scale and other commands are also commonly used.
Apply is the most common way to submit yaml to a Kubernetes cluster, while edit patch is a common means to modify online load. The label and annotation commands are used to modify object metadata, such as labels and comments.
D
There's nothing to say about this-- delete
Get help
All commands and subcommands of kubectl support the-- help parameter, and you can get help in this way.
The kubectl options command can get all the global parameters of kubectl.
Common parameters
-f: many instructions (not just apply and create) can be entered in the form of-f, and if you use a pipe operation, you can receive STDIN input with the parameter-f -.
-l: you can use tags on various objects to filter the scope of operations, such as-l app=hello
-o: specify the output format, this parameter is relatively complex, the most commonly used is yaml or json to output machine messages, you can also use JSON Path or Go Template to process the results.
Object
An object is usually a combination of type and name, and you can use kubectl to obtain the object types supported by the current cluster:
As shown in the figure above, the output contains several columns: name, acronym, API group, whether to belong to the namespace, and the Kind property of the object. For example, the commonly used Deployment:
Name:
Deployment
Abbreviation:
Deploy
API group:
Apps
Home Namespace:
Yes
Kind:
Deployment
Using the command kubectl get deploy, you can get a list of Deployment objects in the current namespace. If you add the name of Deployment to the tail, you can get Deployment objects that meet the name requirements.
Schema
The aforementioned-f parameter, or get-o yaml, uses a specific object data structure. Where is this structure defined? The basic structure can be divided into three parts, taking a Namespace as an example:
ApiVersion: v1
Kind: Namespace
Metadata:
Name: default
Spec:
Finalizers:
-kubernetes
It is generally divided into four basic fields: apiVersion, kind, metadata, status, and spec.
ApiVersion:
The format is /, the API Group of an object can be found using the api-resources command mentioned earlier, and the version can be obtained through the kubectl api-versions query.
Kind:
The field that corresponds to the output of the api-resources command.
Metadata:
Metadata, which includes fields such as labels, comments, names, and so on, and if the object belongs to a namespace, the namespace is also written here.
Status:
The contents of this field are usually filled in automatically by Kubenretes.
It is often omitted.
Spec:
Specific object content, its definition structure can be obtained in several ways
Some resources can be explained using kubectl explain
If the resource has an object in the cluster, you can use kubectl get-o yaml to get the original text and salute it.
If you don't have either of the first two methods, you need to check Kubernetes or a third-party API Reference.
At this point, I believe you have a deeper understanding of "what are the basic knowledge points of kubectl?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.