1.1.概念linux
kubernetes(一般稱爲k8s)用於自動部署、擴展和管理容器化應用程序的開源系統。它旨在提供「跨主機集羣的自動部署、擴展以及運行應用程序容器的平臺」。支持一系列容器工具 ,包括Docker等。git
1.2.特色github
1)可移植:支持公有云、私有云、混合雲、多重雲golang
2)可擴展:模塊化、插件化、可掛載、可組合docker
3)自動化:自動部署、自動重啓、自動複製、自動伸縮/擴展windows
4)快速部署應用,快速擴展應用centos
5)無縫對接新的應用功能api
6)節約資源、優化硬件資源的使用bash
2.kubernetes中的相關概念網絡
2.1.Cluster
計算、存儲和網絡資源的集合,Kubernetes利用這些資源運行各類基於容器的應用
2.2Master
是Cluster的大腦,主要職責是調度,即決定將應用放在哪裏運行。Master運行Linux操做系統,能夠是物理機或者虛擬機。爲了是實現高可用,能夠運行多個Master。
2.3Node
職責是運行容器應用。Node 由 Master 管理,Node 負責監控並彙報容器的狀態,並根據 Master 的要求管理容器的生命週期。Node 運行在 Linux 操做系統,能夠是物理機或者是虛擬機。
2.4Pod
Pod 是 Kubernetes 的最小工做單元。每一個 Pod 包含一個或多個容器。Pod 中的容器會做爲一個總體被 Master 調度到一個 Node 上運行。
2.5Controller
Kubernetes 一般不會直接建立 Pod,而是經過 Controller 來管理 Pod 的。Controller 中定義了 Pod 的部署特性,好比有幾個副本,在什麼樣的 Node 上運行等。爲了知足不一樣的業務場景,
Kubernetes 提供了多種 Controller,包括 Deployment、ReplicaSet、DaemonSet、StatefuleSet、Job 等,
Deployment 是最經常使用的 Controller,好比前面在線教程中就是經過建立 Deployment 來部署應用的。Deployment 能夠管理 Pod 的多個副本,並確保 Pod 按照指望的狀態運行。
ReplicaSet 實現了 Pod 的多副本管理。使用 Deployment 時會自動建立 ReplicaSet,也就是說 Deployment 是經過 ReplicaSet 來管理 Pod 的多個副本,咱們一般不須要直接使用
ReplicaSet。
DaemonSet 用於每一個 Node 最多隻運行一個 Pod 副本的場景。正如其名稱所揭示的,DaemonSet 一般用於運行 daemon。
StatefuleSet 可以保證 Pod 的每一個副本在整個生命週期中名稱是不變的。而其餘 Controller 不提供這個功能,當某個 Pod 發生故障須要刪除並從新啓動時,Pod 的名稱會發生變化。
同時 StatefuleSet 會保證副本按照固定的順序啓動、更新或者刪除。
Job 用於運行結束就刪除的應用。而其餘 Controller 中的 Pod 一般是長期持續運行。
安裝Minikube
Linux
# 也能夠下載最新版,但可能和本文執行環境不一致,會有坑 curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/ minikube -hcurl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.7.1/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
因爲kubenetes域名背牆(gcr.io),如kubernetes-dashboard服務依賴不能正常使用。
阿里雲提供了minikube修改版
下載golang和docker
cd /etc/yum.repos.d/ && curl -o docker-ce.repo https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo yum clean all yum makecache yum install go docker-ce -y
啓動
minikube start --registry-mirror=https://docker.mirrors.ustc.edu.cn/
安裝Kubectl
kubectl即kubernetes的客戶端,經過他能夠進行相似docker run等容器管理操做
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/ kubectl -h
查看版本
[root@yanglin5 ~]# minikube version minikube version: v1.0.1 [root@yanglin5 ~]# kubectl version Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.2", GitCommit:"66049e3b21efe110454d67df4fa62b08ea79a19b", GitTreeState:"clean", BuildDate:"2019-05-16T16:23:09Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"} The connection to the server localhost:8080 was refused - did you specify the right host or port?
啓動程序
啓動minikube
minikube start
首次啓動會下載localkube,下載過程可能會失敗,會有以下提示,重試幾回便可
Starting local Kubernetes v1.8.0 cluster... Starting VM... Downloading Minikube ISO 64.70 MB / 140.01 MB [====================>-----------------------] 46.21% 14s E0105 14:06:03.884826 10434 start.go:150] Error starting host: Error attempting to cache minikube ISO from URL: Error downloading Minikube ISO: failed to download: failed to download to temp file: failed to copy contents: read tcp 10.0.2.15:47048->172.217.24.16:443: read: connection reset by peer. ================================================================================ An error has occurred. Would you like to opt in to sending anonymized crash information to minikube to help prevent future errors? To opt out of these messages, run the command: minikube config set WantReportErrorPrompt false ================================================================================ Please enter your response [Y/n]:
若是下載成功,可是報了諸如VBoxManage not found這樣的錯誤,以下
Starting local Kubernetes v1.8.0 cluster... Starting VM... Downloading Minikube ISO 140.01 MB / 140.01 MB [============================================] 100.00% 0s E0105 14:10:00.035369 10474 start.go:150] Error starting host: Error creating host: Error executing step: Running precreate checks. : VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path. Retrying. E0105 14:10:00.035780 10474 start.go:156] Error starting host: Error creating host: Error executing step: Running precreate checks. : VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path ================================================================================ An error has occurred. Would you like to opt in to sending anonymized crash information to minikube to help prevent future errors? To opt out of these messages, run the command: minikube config set WantReportErrorPrompt false ================================================================================ Please enter your response [Y/n]:
解決辦法是安裝 VirtualBox【對於windows或者mac】 再從新啓動;固然若是你是Linux,也能夠執行以下命令啓動minikube,此時就不須要安裝VirtualBox了。
由於minikube默認須要虛擬機來初始化kunernetes環境,但Linux是個例外,能夠追加–vm-driver=none參數來使用本身的環境,說明見https://github.com/kubernetes/minikube#quickstart
# linux 下獨有,不依賴虛擬機啓動 sudo minikube start --vm-driver=none # 若是是Mac or Windows,安裝VirtualBox後再從新start便可 sudo minikube start
若是安裝了虛擬機,或者使用了–vm-driver=none參數,而且下載完畢,會有以下提示運行成功
Starting local Kubernetes v1.8.0 cluster... Starting VM... Getting VM IP address... Moving files into cluster... Downloading localkube binary 148.25 MB / 148.25 MB [============================================] 100.00% 0s 0 B / 65 B [----------------------------------------------------------] 0.00% 65 B / 65 B [======================================================] 100.00% 0sSetting up certs... Connecting to cluster... Setting up kubeconfig... Starting cluster components... Kubectl is now configured to use the cluster. =================== WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory. You will need to move the files to the appropriate location and then set the correct permissions. An example of this is below: sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration sudo chown -R $USER $HOME/.kube sudo chgrp -R $USER $HOME/.kube sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration sudo chown -R $USER $HOME/.minikube sudo chgrp -R $USER $HOME/.minikube This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true Loading cached images from config file.