帶你玩轉Kubernetes

來源:互聯網
上載者:User

標籤:google   管理系統   雲平台   server   虛擬機器   

導讀 Kubernetes是著名的容器管理系統,是一個有這很多貢獻者的開源大項目,它作為一個不挑食的容器管理架構,可以無處不在。這兩天接觸K8s,帶你玩轉K8s,這個教程可以大致讓你知道運行更改源碼,而且從頭測試本地Kubernetes平台叢集。

Kubernetes是個有很多貢獻者的開源大項目,理論上它作為一個不挑食的容器管理架構,可以無處不在。但可惜的是,無論實際編寫還是貢獻測試代碼,引導kubernetes server都不太容易。裡邊的一些檔案對於我來說有些亂,不是掛了的就是過時的。源檔案更改和編譯啟動並執行樣本非常少,如果本地跑kubernets cluster就必須從頭開始摸索中前進。
下面分享一些摸索心得,盡量從頭開始詳細講解,大家一起聊聊。

步驟1:建立虛擬機器並訪問

既然是從頭開始,那就得做做樣子。先建立個新的、乾淨的VM來運行。

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-1.jpg" width="595" height="831" class="alignnone size-full wp-image-63500" style="height:auto;" />

至此,新的Google雲平台VM執行個體建立完成,這是個乾淨無汙染的新環境。

步驟2:為Kubernetes準備虛擬機器

這一步要安裝:

GCC,Make,socat和git;Docker;其他的看自己需求,沒啥需求就不用管了。

ssh到上面的新VM,安裝GCC,Make,socat和git:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-2.png" width="640" height="78" class="alignnone size-full wp-image-63501" style="height:auto;" />
安裝etcd:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-3.png" width="640" height="59" class="alignnone size-full wp-image-63502" style="height:auto;" />
安裝golang(應該是1.8+版本):

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-4.png" width="640" height="112" class="alignnone size-full wp-image-63503" style="height:auto;" />

步驟3:擷取Kubernetes原始碼

在這個步驟,Git Kubernetes原始碼會複製下來並添加到GOPATH。注意,這裡要用–depth 1,即只要最新版本。

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-5.png" width="640" height="59" class="alignnone size-full wp-image-63504" style="height:auto;" />

把Kubernetes sources添加到GOPATH:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-6.png" width="1200" height="150" class="alignnone size-full wp-image-63505" style="height:auto;" />

步驟4:編譯並運行Kubernetes

這裡不難,因為它正好有個叫local-up-cluster.sh的好貨。
650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-7.png" width="640" height="74" class="alignnone size-full wp-image-63506" style="height:auto;" />

輸出顯示:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-8.jpg" width="640" height="319" class="alignnone size-full wp-image-63507" style="height:auto;" />

步驟5:測試Kubernetes

虛擬機器開啟個新的shell,cd到Kubernetes來源目錄GOPATH,然後就可以測試了:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-9.jpg" width="640" height="202" class="alignnone size-full wp-image-63508" style="height:auto;" />

步驟6:更改原始碼

在kubernetes-apiserver添加日誌行來改個entry point,而且要保證這條你能在日誌中看到:
650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-10s.jpg" width="640" height="195" class="alignnone size-full wp-image-63509" style="height:auto;" />

步驟7:測試Kubernetes原始碼的更改

停止本地群集,重啟[email protected]:/gopath/src/k8s.io/kubernetes# hack/local-up-cluster.sh

在尾api server日誌行檢查下是否出現了更改:

650) this.width=650;" src="http://www.linuxprobe.com/wp-content/uploads/2017/04/k8s-11.jpg" width="640" height="99" class="alignnone size-full wp-image-63510" style="height:auto;" />

這就是從頭開始建立本地的Kubernetes叢集的文檔,不麻煩,但也包含了一些比較重要的點:執行了幾個簡單的步驟,擷取一個Kubernetes叢集,並編譯並更改了API伺服器,然後查看了更改。

文章來自:公眾號:DevOps研究院


原文地址:http://www.linuxprobe.com/k8s-use-play.html

本文出自 “小華的部落格” 部落格,請務必保留此出處http://coderhsf.blog.51cto.com/12629645/1921749

帶你玩轉Kubernetes

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.