Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Kubernetes command line management tool Kubectl

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about how to use the Kubernetes command line management tool Kubectl, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

I. domestic installation of Kubectl

The installation commands provided on the official website are:

Curl-LO https://storage.googleapis.com/kubernetes-release/release/$(curl-s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl

Domestic direct installation of Kubectl will fail mainly because you have accessed the address of google, but you can find compiled binaries through Github.

Execute installation command

Wget https://dl.k8s.io/v1.15.3/kubernetes-client-linux-amd64.tar.gztar-zxvf kubernetes-client-linux-amd64.tar.gzcd kubernetes/client/binchmod + x. / kubectlsudo mv. / kubectl / usr/local/bin/kubectl

Kubectl version can see the output normally.

II. Configuration file

It is not enough to have the Kubectl command to operate the K8S cluster. You must fill in the configuration information related to the link to K8S. By default, kubectl will look for the configuration file in ~ / .kube/config

Vim ~ / .kube/configapiVersion: v1clusterscluster: server: https://xxxxxxxxxx:443 insecure-skip-tls-verify: true name: kubernetescontexts:- context: cluster: kubernetes user: "kubernetes-admin" name: kubernetes-admin-xxxxxxcurrent-context: kubernetes-admin-xxxxxxxxkind: Configpreferences: {} users:- name: "kubernetes-admin" user: xxxxxxxx

The control of the K8S cluster can be performed through the command line.

Kubectl versionClient Version: version.Info {Major: "1", Minor: "10", GitVersion: "v1.10.5", GitCommit: "32ac1c9073b132b8ba18aa830f46b77dcceb0723", GitTreeState: "clean", BuildDate: "2018-06-21T11:46:00Z", GoVersion: "go1.9.3", Compiler: "gc", Platform: "darwin/amd64"} Server Version: version.Info {Major: "1", Minor: "11", GitVersion: "v1.11.5", GitCommit: "753b2dbc622f5cc417845f0ff8a77f539a4213ea", GitTreeState: "clean" BuildDate: "2018-11-26T14:31:35Z", GoVersion: "go1.10.3", Compiler: "gc", Platform: "linux/amd64"}

Of course, you can also specify the corresponding file path as the configuration file.

Kubectl-- kubeconfig=~/.kubu/config xxxxxxxxxx III, Kubectl common command kubectl apply-configure resources through file name or console input. Kubectl create-create a resource through a file name or console input. Kubectl delete-Delete resources through file name, console input, resource name, or label selector. Kubectl edit-Editing resources on the server side. Kubectl exec-executes commands inside the container. Kubectl get-outputs one or more resources. Kubectl logs-outputs the log of a container in pod. Kubectl namespace-(disabled) sets or views the namespace currently in use. Kubectl port-forward-forwards the local port to Pod. Kubectl rolling-update-performs a rolling upgrade of the specified replication controller. Kubectl stop-(disabled) enter the secure delete resource through the resource name or console. Kubectl version-outputs version information for both the server and the client. Basic Commands (Beginner): create Create a resource from a file or from stdin. Expose uses replication controller, service, deployment or pod and exposes it as a new Kubernetes Service run to run a specified image in the cluster. Set sets a specified feature for objects. Run-container runs a specified image in the cluster. This command is deprecated, use "run" insteadBasic Commands (Intermediate): get displays one or more documents for resources explain viewing resources edit edits a resource on the server delete Delete resources by filenames, stdin, resources and names, or by resources and label selectorDeploy Commands: rollout Manage the rollout of a resource rolling-update completes the specified rolling upgrade of ReplicationController scale to Deployment, ReplicaSet ReplicationController or Job set a new number of replicas autoscale automatically adjusts the number of copies of a Deployment, ReplicaSet, or ReplicationController Cluster Management Commands: certificate modifies the certificate resource. Cluster-info displays cluster information top Display Resource (CPU/Memory/Storage) usage. Cordon mark node for unschedulable uncordon mark node for schedulable drain Drain node in preparation for maintenance taint update taintsTroubleshooting and Debugging Commands on one or more node: describe displays resources details of a specified resource or group logs output container log attach Attach in pod to a running container exec execute a command in a container Port-forward Forward one or more local ports to a pod proxy runs a proxy to Kubernetes API server cp to copy files and directories to containers and copy files and directories from the container. Auth Inspect authorizationAdvanced Commands: apply configures a resource through a file name or standard input stream (stdin) patch updates a resource's field (s) replace using strategic merge patch to replace a resource convert through filename or stdin in a different API versions conversion profile Settings Commands: label updates labels annotate on this resource Update the comments for a resource completion Output shell completion code for the specified shell (bash or zsh) Other Commands: api-versions Print the supported API versions on the server In the form of "group/version" config modifies kubeconfig file help Help about any command plugin Runs a command-line plugin version output client and server version information above is how to use the Kubernetes command line management tool Kubectl The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report