Kubernetes Command Line Management Tool-Kubectl

Keywords: Programming Kubernetes Linux github curl

Enclosed:

Meow a Mimi's blog: w-blog.cn Kubernetes official documents: https://kubernetes.io/docs/reference/ Kubernetes official Git address: https://github.com/kubernetes/kubernetes

PS: This series uses Kubernetes V1.8 Rancher V1.6.14

I. Installation of Kubectl in China

The installation commands provided by 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

Direct installation of Kubectl in China will fail mainly by accessing google's address, but you can find the compiled binary files on Github.

Visit the following websites: kubernetes/CHANGELOG.md at master · kubernetes/kubernetes · GitHub

Find the Kubectl version you want to install and click Enter

Find Client Binaries

Choose different installation package addresses for more system versions

Execute installation commands

wget https://dl.k8s.io/v1.15.3/kubernetes-client-linux-amd64.tar.gz
tar -zxvf kubernetes-client-linux-amd64.tar.gz
cd kubernetes/client/bin
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

kubectl version can see the output normally

Configuration files

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

vim ~/.kube/config

apiVersion: v1
clusters:
- cluster:
    server: https://xxxxxxxxxx:443
    insecure-skip-tls-verify: true
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: "kubernetes-admin"
  name: kubernetes-admin-xxxxxx
current-context: kubernetes-admin-xxxxxxxx
kind: Config
preferences: {}
users:
- name: "kubernetes-admin"
  user: xxxxxxxx

You can execute control over the K8S cluster from the command line

kubectl version
Client 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 a configuration file.

kubectl  --kubeconfig=~/.kubu/config xxxxxxxxxx

Common Kubectl commands

kubectl apply --- Configure resources by entering file names or consoles.
kubectl create - Create resources by entering a file name or console.
kubectl delete --- Delete resources by filename, console input, resource name, or label selector.
kubectl edit - Edit the resources on the server side.
kubectl exec - Execute commands inside the container.
kubectl get --- outputs one / more resources.
kubectl logs - Outputs the log of a container in a pod.
kubectl namespace - (disabled) sets or views the currently used namespace.
kubectl port-forward --- Forward the local port to Pod.
kubectl rolling-update - performs a rolling upgrade on the specified replication controller.
kubectl stop -- (disabled) Enter a safe deletion of resources through the resource name or console.
kubectl version - Outputs version information for both the server and client.
Basic Commands (Beginner):
  create         Create a resource from a file or from stdin.
  expose         Use replication controller, service, deployment perhaps pod And expose it as a new one
Kubernetes Service
  run            Running a specified image in the cluster
  set            by objects Set a specified feature
  run-container  Running a specified image in the cluster. This command is deprecated, use "run" instead

Basic Commands (Intermediate):
  get            Display one or more resources
  explain        View documentation of resources
  edit           Editing a resource on the server
  delete         Delete resources by filenames, stdin, resources and names, or by resources and label selector

Deploy Commands:
  rollout        Manage the rollout of a resource
  rolling-update Complete the specified ReplicationController Scroll Upgrade
  scale          by Deployment, ReplicaSet, Replication Controller perhaps Job Set a new number of copies
  autoscale      Automatically adjust one Deployment, ReplicaSet, perhaps ReplicationController Number of copies

Cluster Management Commands:
  certificate    modify certificate Resources.
  cluster-info   Display cluster information
  top            Display Resource (CPU/Memory/Storage) usage.
  cordon         sign node by unschedulable
  uncordon       sign node by schedulable
  drain          Drain node in preparation for maintenance
  taint          Update one or more node Upper taints

Troubleshooting and Debugging Commands:
  describe       Display a specified resource perhaps group Of resources details
  logs           The output container is in the pod Log in
  attach         Attach To a running container
  exec           In one container To execute a command
  port-forward   Forward one or more local ports to a pod
  proxy          Run one proxy reach Kubernetes API server
  cp             copy files and directories reach containers And copying from containers files and directories.
  auth           Inspect authorization

Advanced Commands:
  apply          Input stream by file name or standard(stdin)Allocation of resources
  patch          Use strategic merge patch Updating a resource field(s)
  replace        adopt filename perhaps stdin Replace a resource
  convert        In different API versions Conversion Profile

Settings Commands:
  label          Update on this resource labels
  annotate       Update annotations 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         modify kubeconfig file
  help           Help about any command
  plugin         Runs a command-line plugin
  version        output client and server Version information

Posted by jannz on Thu, 29 Aug 2019 00:53:21 -0700