Connecting the public cloud Kubernetes cluster through kubectl

Keywords: Kubernetes curl Linux MySQL

Kubectl is a command-line tool for Kubernetes cluster. Through kubectl, the cluster itself can be managed and the container application can be installed and deployed on the cluster. It can not only deploy master and node nodes, but also manage Kubernetes on other machines.

Official documents: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos

I. Software Installation

1. Installation of macOS using two-machine packages

1,Download software (latest version)
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s  

2,Give executive authority
chmod +x ./kubectl
3,Copy it to a directory that has been added to the environment variable Facilitate late execution
sudo mv ./kubectl /usr/local/bin/kubectl
4,Execute command testing
kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.6-aliyun.1", GitCommit:"a4182a8", GitTreeState:"", BuildDate:"2019-08-27T06:03:13Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

2. Install on CentOS 7.x using binary packages

1. Download Software

curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s  
Specified version
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.13.5/bin/linux/amd64/kubectl 
If you want to download the latest version of the installation package, use the following command: simply replace v1.13.5 with $(curl-s https://storage.googleapis.com/kubernetes-release/release/stable.txt)

2. Entrusting Execution Authority
chmod +x ./kubectl
 3. Copy it to a directory that has been added to the environment variable for later execution
sudo mv ./kubectl /usr/local/bin/kubectl
 4, test
[root@izuf6beunt2a2ki2nqvphuz ~]# kubectl  version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.6-aliyun.1", GitCommit:"a4182a8", GitTreeState:"", BuildDate:"2019-08-27T06:03:13Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}

Second, configure it to have access to Kubernetes

After creating the Kubernetes cluster on Aliyun, you can see the following part of the basic information in cluster management that connects the Kubernetes cluster through kubectl(Managing clusters through CloudShell ) Relevant guidance documents, according to their document configuration, can be divided into intranet and extranet. Machines with the same VPC node in Aliyun and node can be regarded as intranet, while accessing SLB (load balancing for Kubernetes cluster) extranet IP can be regarded as extranet access. Aliyun gives two configuration files very carefully.

In the first step, CentOS 7.X is configured for the Intranet, using the Intranet-related configuration files

The root account home directory/.kube/config file of the machine is copied into it.

apiVersion: v1
clusters:
- cluster:
    server: https://10.101.175.223:6443
    certificate-authority-data: CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURHakNDQWdLZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREErTVNjd0ZBWURWUVFLRXcxaGJHbGkKWVdKaElHTnNiM1ZrTUE4R0ExVUVDaE1JYUdGdVozcG9iM1V4RXpBUkJnTlZCQU1UQ210MVltVnlibVYwWlhNdwpIaGNOTVRrd09URTRNRFl6TURFeVdoY05Namt3T1RFMU1EWXpNREV5V2pBK01TY3dGQVlEVlFRS0V3MWhiR2xpCllXSmhJR05zYjNWa01BOEdBMVVFQ2hNSWFHRnVaM3BvYjNVeEV6QVJCZ05WQkFNVENtdDFZbVZ5Ym1WMFpYTXcKZ2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRQzI3UFM5Z0g1UW00UDBDQWpMOVpvagpYTWNZQjhYbUJ0R1pUMG1ydFhpcUppdlFVc1crRi9xNlUyN3VFeEp1Q01ndFBxNGVnd01NbWdKU1VLQkFmeDdqCko0SmRyeU5wdFhmd05ZenpHSTRJVUF3VndLa1paTkJXWld1REFuTDBoNDZFL01MeEs5eUgvQ0lSQXM5TWl6UFoKckg4T3VRR25mRmROVVd1SVIzTElCaTREMjdZaEJhZDhEaWdaMWFpWGdxY3hRTSt4cHpNR09DUzFlWW04dDZVMwpHSFg1TXBuYysyQlUyTk5Oay8wQmdCc1F4R1MyUndoSVBrVjFRdFRyWXRwTEI0NFRPYmg3NFVSVkxzbzRqcTFlCkVHUjhFSTNxNy8xVFkxSXUzRVE5enZac3dOVHRHR1BBNUhGWmJtM2dJVHovNmp2cU41Z09XenZwNGd4QzNtaFgKQWdNQkFBR2pJekFoTUE0R0ExVWREd0VCL3dRRUF3SUNwREFQQmdOVkhSTUJBZjhFQlRBREFRSC9NQTBHQ1NxRwpTSWIzRFFFQkN3VUFBNElCQVFBbXZraIUUxTWEMzVXRua0RlaXAzWXNHcWhPVElMTkxxQ1RIVlk2aDdDWnMxCng3U0ZtN3JONGMzSU90eGpySXJ3S2RNUlE5QVdGek0yT0lNTFlQS3F4Mzk1NWE2SFlOdGhPbFNLTi9MamFCQ3MKRHpHd1k5dU5ablNGRzFMdVpmM2dMRjA2eit0dkJqWThReTUzRkdPdVJTcHpDcXlsN2dKWTRWV0xIcGhBZVV1dQpUUHRRYnNsMm5rMldIYlJzS1RlTnlhemt4YkMvY2hiZUJXQW5DZzhPWGhSRVB3T2pXdndScXlLR3VPbXhxVWhDCndMd1BvZUtRQXlCWG9maUUxZ0F4Zy9jM3dzaFI1d1B2dGhXdERzd21CUE44d2JPNXNibGRjWVhXMEt6eTc2d2wKRDVDbHYvZFNaNENhaUNidUJ6aW1xZXVtd24xL0xhRnI4eEgvK0lTOAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: "kubernetes-admin"
  name: kubernetes-admin-cfd09da28dcfb4ad8856a5e57ab43f221
current-context: kubernetes-admin-cfd09da28dcfb4ad8856a5e57ab43f221
kind: Config
preferences: {}
users:
- name: "kub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d5blV2UUlEQVFBQgpBb0dBSE5HcFRxVTV0L1kxWUdDakpEeEM2VFN5ZEh1Q0czTFlVMmtDdnVsRGNzL0NYcGIvUU5HMTdpTENZSHRSCkN1Y2twcFRaZWEzbzdUU1ZZcjRkbTZCbStWdVpHM3NDaGdZSWNhQVVXOG1PQThYTEFTZDk5QUZkQmIzY0YxRDgKTTZnZnFpNW1VM2s1NUZrTjhSWkxtN1RlNWtsYlNydU0vQ2tOMUF2TW9IdmhTZ0VDUVFEbTVBcW9vbWp0VytjQwpLdlBkcHl1REgvM3VIaEFvSmZXeGJsUmRUQm5iQmNHbC91aWVPbUhudjdIMXFwejRXLy94cUNXWm5XT1VvMFU1CnZYeDVadWV0QWtFQTdIWTdBM1NxenlPWjF6MkhwcnRTVHFLQlNvY1FyRUhPWXNZWmhJZ1JWdFFCendyall5NjgKeERoN2tiTjZBS2V4T2dQL3FyMUtSMjdISWNtWW11R0RVUUpBWEFCT0J2Z0FHMlJkWGszRE1uVWtMM0dWKzBYYgpaa1FKN0pOcjVta21mRkdFNGlINml1SDBsU1diUWFxa05ZcGpKK1c2WmNXREluMFVYbmVVbThOWFdRSkJBS2szCjR2dVNIanFtUzQzUkpxYVhIMHZPMTUreUVLaDFYM0VvTzFLdzNWZTUyS0dHTlR2aFVvMUpyb1NTWUJqZjZPQ1AKeEFNMysxUXJYcTQ3U3M1cjNFRUNRRlBjYUkvTTVYdkZMWkJablRlSjFYd2w4Y3dxVkY3TlMzNGlrMUtjVWxZNQpveDFLOCtEK1FBV0MxNnM3VUNSN1k2VXhEZDIwajNNclZnUTN6S3JtN1VNPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=

Execute relevant command validation

[root@izuf6beunt2a2ki2nqvphuz ~]# kubectl  get  nodes
NAME                         STATUS   ROLES    AGE   VERSION
cn-shanghai.10.101.175.227   Ready    <none>   33h   v1.14.6-aliyun.1
[root@izuf6beunt2a2ki2nqvphuz ~]# kubectl  get  pods
NAME                        READY   STATUS    RESTARTS   AGE
dashbord-7fbdc69845-fx76j   1/1     Running   0          26h
mysql-0                     1/1     Running   0          24h
mysql-1                     0/1     Pending   0          24h
redis-0                     1/1     Running   0          24h
[root@izuf6beunt2a2ki2nqvphuz ~]# kubectl  get  namespaces
NAME              STATUS   AGE
ahas              Active   27h
catalog           Active   24h
default           Active   33h
kube-node-lease   Active   33h
kube-public       Active   33h
kube-system       Active   33h
nginx-web         Active   32h

Configuring Ali Cloud Extranet Access on MAC will cause an error when it is saved directly by vi $HOME/.kube/config. You can choose to create a $HOME/.kube/directory first, and then fill in the configuration file without further error. Here is the verification process after configuring.

kubectl  get pods
NAME                        READY   STATUS    RESTARTS   AGE
dashbord-7fbdc69845-fx76j   1/1     Running   0          27h
mysql-0                     1/1     Running   0          25h
mysql-1                     0/1     Pending   0          24h
redis-0                     1/1     Running   0          25h

kubectl  get  namespaces
NAME              STATUS   AGE
ahas              Active   27h
catalog           Active   24h
default           Active   33h
kube-node-lease   Active   33h
kube-public       Active   33h
kube-system       Active   33h
nginx-web         Active   32h

It is obvious that the execution of the external network is much slower than that of the internal network, which depends mainly on the bandwidth and network quality of the public network. The commands related to kubectl can refer to official documents and public cloud product documents.

Official documents: https://kubernetes.io/docs/reference/kubectl/kubectl/

Ali cloud https://help.aliyun.com/document_detail/93080.html?spm=a2c4g.11174283.6.964.3b972ceeYhCcoS

HUAWEI cloud: https://support.huaweicloud.com/usermanual-cce/cce_01_0023.html

Ucloud Public Cloud: https://docs.ucloud.cn/compute/uk8s/manageviakubectl/intro_of_kubectl


Posted by mikesab on Fri, 20 Sep 2019 01:23:57 -0700