您好,登錄后才能下訂單哦!
? ? kubectl是Kubernetes集群的命令行工具,通過(guò)kubectl能夠?qū)罕旧磉M(jìn)行管理,并能夠在集群上進(jìn)行容器化應(yīng)用的安裝部署,不僅可以部署master、node節(jié)點(diǎn),還可以部署到其他機(jī)器上管理Kubernetes。
官方文檔:https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos
一、軟件安裝
1、使用二機(jī)制包在macOS安裝
1、下載軟件(最新版本) curl?-LO?https://storage.googleapis.com/kubernetes-release/release/$(curl?-s?? 2、賦予執(zhí)行權(quán)限 chmod?+x?./kubectl 3、將其拷貝到已經(jīng)添加到環(huán)境變量的某個(gè)目錄中?方便后期執(zhí)行 sudo?mv?./kubectl?/usr/local/bin/kubectl 4、執(zhí)行命令測(cè)試 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、使用二進(jìn)制包在CentOS 7.x上面安裝
1、下載軟件 curl?-LO?https://storage.googleapis.com/kubernetes-release/release/$(curl?-s?? 指定版本 curl?-LO?https://storage.googleapis.com/kubernetes-release/release/v1.13.5/bin/linux/amd64/kubectl? 如果您要下載最新版本的安裝包,使用如下命令即可:?僅需將v1.13.5替換為$(curl?-s?https://storage.googleapis.com/kubernetes-release/release/stable.txt)即可 2、賦予執(zhí)行權(quán)限 chmod?+x?./kubectl 3、將其拷貝到已經(jīng)添加到環(huán)境變量的某個(gè)目錄中?方便后期執(zhí)行 sudo?mv?./kubectl?/usr/local/bin/kubectl 4、測(cè)試 [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"}
二、配置其能夠訪問(wèn)Kubernetes
? ?在阿里云上面創(chuàng)建好Kubernetes集群后,在集群管理里面基本信息的下面部分可以看到通過(guò) kubectl 連接 Kubernetes 集群?(通過(guò) CloudShell 管理集群)的相關(guān)指導(dǎo)文檔,根據(jù)其文檔配置就好了,分為內(nèi)網(wǎng)和外網(wǎng)情況,在阿里云和node節(jié)點(diǎn)同一VPC的機(jī)器可以視為內(nèi)網(wǎng),而訪問(wèn)SLB(為Kubernetes集群提供負(fù)載均衡的)外網(wǎng)IP視為外網(wǎng)訪問(wèn),阿里云很貼心的給出了2份配置文件。
?在第一步里面CentOS 7.X 配置的為內(nèi)網(wǎng),使用內(nèi)網(wǎng)相關(guān)的配置文件
在該機(jī)器的root賬戶家目錄/.kube/config文件并將相關(guān)的配置復(fù)制到里面,
apiVersion:?v1 clusters: -?cluster: ????server:?https://10.101.175.223:6443 ????certificate-authority-data:?CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURHakNDQWdLZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREErTVNjd0ZBWURWUVFLRXcxaGJHbGkKWVdKaElHTnNiM1ZrTUE4R0ExVUVDaE1JYUdGdVozcG9iM1V4RXpBUkJnTlZCQU1UQ210MVltVnlibVYwWlhNdwpIaGNOTVRrd09URTRNRFl6TURFeVdoY05Namt3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2pXdndScXlLR3VPbXhxVWhDCndMd1BvZUtRQXlCWG9maUUxZ0F4Zy9jM3dzaFI1d1B2dGhXdERzd21CUE44d2JPNXNibGRjWVhXMEt6eTc2d2wKRDVDbHYvZFNaNENhaUNidUJ6aW1xZXVtd24xL0xhRnI4eEgvK0lTOAotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg== ??name:?kubernetes contexts: -?context: ????cluster:?kubernetes ????user:?"kubernetes-admin" ??name:?kubernetes-admin-cfd09da28dcfb4ad8856a5e57ab43f221 current-context:?kubernetes-admin-cfd09da28dcfb4ad8856a5e57ab43f221 kind:?Config preferences:?{} users: -?name:?"kubernetes-admin" ??user: ????client-certificate-data:?CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN6VENDQWphZ0F3SUJBZ0lERVpLTk1BMEdDU3FHU0liM0RRRUJDd1VBTUdveEtqQW9CZ05WQkFvVElXTm0KWkRBNVpHRXlPR1JqWm1JMFlXUTRPRFUyWVRWbE5UZGhZalF6WmpJeU1URVFNQTRHQTFVRUN4TUhaR1ZtWVhWcwpkREVxTUNnR0ExVUVBeE1oWTJaa01EbGtZVEk0WkdObVlqUmhaRGc0TlRaaE5XVTFOMkZpTkRObU1qSXhNQjRYCkRURTVNRGt4T0RFeU1UTXdNRYRFRJeU1Ea3hOekV5TVRnek5Wb3dQekVYTUJVR0ExVUVDaE1PYzNsemRHVnQKT20xaGMzUmxjbk14Q1RBSEJnTlZCQXNUQURFWk1CY0dBMVVFQXhNUWEzVmlaWEp1WlhSbGN5MWhaRzFwYmpDQgpuekFOQmdrcWhraUc5dzBCQVFFRkFBT0JqUUF3Z1lrQ2dZRUExVVRjS2d2Tjk2dzFZUkhvallMZHMzRnJ6Sm8wCjdXbFVsdEU3cVdVZ2ZsdTZIUEpMSnh4dFVsalJKaGNyYkxJTnp6K1kwVVRDSFJEMDRWZ2VXRWc2R21tOWRFWU0KZUI0TEsvNVp5ejF3Kzd1R0c5cC9pTi8vY1pxZUNBd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eEFNMysxUXJYcTQ3U3M1cjNFRUNRRlBjYUkvTTVYdkZMWkJablRlSjFYd2w4Y3dxVkY3TlMzNGlrMUtjVWxZNQpveDFLOCtEK1FBV0MxNnM3VUNSN1k2VXhEZDIwajNNclZnUTN6S3JtN1VNPQotLS0tLUVORCBSU0EgUFJJVkFURSBLRVktLS0tLQo=
執(zhí)行相關(guān)命令驗(yàn)證
[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
在MAC上配置阿里云外網(wǎng)訪問(wèn)是直接vi??$HOME/.kube/config 保存時(shí)會(huì)報(bào)錯(cuò),可以選擇先創(chuàng)建?$HOME/.kube/目錄,然后填寫(xiě)配置文件就不會(huì)再報(bào)錯(cuò),下面是配置后的驗(yàn)證過(guò)程,
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
很明顯的發(fā)現(xiàn)外網(wǎng)的執(zhí)行要比內(nèi)網(wǎng)要慢很多,這個(gè)主要取決于公網(wǎng)的帶寬和網(wǎng)絡(luò)質(zhì)量,kubectl相關(guān)的命令可以參考官方文檔和公有云產(chǎn)品文檔
官方文檔:https://kubernetes.io/docs/reference/kubectl/kubectl/
阿里云?https://help.aliyun.com/document_detail/93080.html?spm=a2c4g.11174283.6.964.3b972ceeYhCcoS
華為云:https://support.huaweicloud.com/usermanual-cce/cce_01_0023.html
Ucloud公有云:https://docs.ucloud.cn/compute/uk8s/manageviakubectl/intro_of_kubectl
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。