Kubernetes學(xué)習(xí)之一:Ubuntu16安裝K8S

環(huán)境依賴(lài):

4臺(tái)機(jī)器,安裝ubuntu16.04吟榴;1臺(tái)master;2臺(tái)node囊扳;1臺(tái)harbor吩翻;


安裝過(guò)程:

整體流程梳理為先安裝master節(jié)點(diǎn),然后再安裝node節(jié)點(diǎn)锥咸,最后安裝harbor(以裸機(jī)只安裝了ubuntu16開(kāi)始):

0狭瞎,配置hosts網(wǎng)絡(luò)發(fā)現(xiàn):

sudo vim /etc/hosts

10.10.30.76 k8smaster?
10.10.30.75 k8snode1
10.10.30.74 k8snode2
10.10.30.73 harbor

1,配置apt國(guó)內(nèi)源:(本文使用的是阿里源搏予,這樣會(huì)提高很多速度)

//打開(kāi)源的配置文件
sudo vim /etc/apt/sources.list

//刪除原有的內(nèi)容熊锭,如果擔(dān)心的話(huà)可以先備份之前的內(nèi)容,然后拷貝內(nèi)容進(jìn)入文件
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

//保存后運(yùn)行
sudo apt-get update

2,安裝Docker:(如果在后面kubernetes配置后不想看見(jiàn)warning碗殷,那么就需要選擇版本低于等于19)

//安裝基礎(chǔ)包
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common

//安裝GPG證書(shū)
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

//使用國(guó)內(nèi)docker源提高速度
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

//更新并安裝docker-ce精绎,如果需要安裝指定版本則進(jìn)行如下編輯,安裝最新版本就不需要指定版本號(hào)
sudo apt-get -y update
sudo apt-get -y install docker-ce=19.03.0~3-0~ubuntu-xenial

3锌妻,安裝kubelet代乃,kubeadm,kubectl:

//安裝依賴(lài)
sudo apt-get update && apt-get install -y apt-transport-https

//安裝GPG證書(shū)
sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -

//使用國(guó)內(nèi)kubernetes的源(阿里源)
sudo vim? /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main

//更新源后進(jìn)行安裝
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl

//關(guān)閉swap和防火墻从祝,否則kubernetes會(huì)啟動(dòng)失敗
sudo swapoff -a
sudo vim /etc/fstab #注釋有swap的行

// 修改cgroupfs襟己,否則會(huì)報(bào)錯(cuò)
sudo vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf? #增加 --cgroup-driver=cgroupfs 在環(huán)境里

//重啟kubelet
sudo systemctl daemon-reload
sudo systemctl restart kubelet

//初始化k8s集群,192的地址就是master的地址根據(jù)自己情況進(jìn)行修改牍陌,cidr和pod必須配置否則沒(méi)有網(wǎng)絡(luò)插件后面的node不能加入
kubeadm init --apiserver-advertise-address=192.168.20.147 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

[init] Using Kubernetes version: v1.20.1 [preflight] Running pre-flight checks
[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03 [preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names
[kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local pcno6] and IPs [10.1.0.1 10.10.30.76]
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [localhost pcno6] and IPs [10.10.30.76 127.0.0.1 ::1]
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [localhost pcno6] and IPs [10.10.30.76 127.0.0.1 ::1]
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Starting the kubelet
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 21.501296 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster [upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node pcno6 as control-plane by adding the labels "node-role.kubernetes.io/master=''" and "node-role.kubernetes.io/control-plane='' (deprecated)"
[mark-control-plane] Marking the node pcno6 as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule] [bootstrap-token] Using token: 4xic6x.jhcftora8nvnlbt9
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token [bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
?????mkdir -p $HOME/.kube
?????sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
?????sudo chown $(id -u):$(id -g) $HOME/.kube/config
?Alternatively, if you are the root user, you can run:
?????export KUBECONFIG=/etc/kubernetes/admin.conf
?You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
?????https://kubernetes.io/docs/concepts/cluster-administration/addons/
?Then you can join any number of worker nodes by running the following on each as root:
?????kubeadm join 10.10.30.76:6443 --token 4xic6x.jhcftora8nvnlbt9 \ --discovery-token-ca-cert-hash sha256:d23cc3c4aba172df962ecb8735292793cb7a101965ffa71631bf50e593c31904

//安裝init的輸出提示start你的cluster
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

// 安裝flannel擎浴,這是k8s必須的一個(gè)插件,國(guó)外源無(wú)法直接下載毒涧,所以要先加dns
sudo vim /etc/hosts #在最后增加:199.232.28.133 raw.githubusercontent.com
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sed 's/quay.io\/coreos/registry.cn-beijing.aliyuncs.com\/imcto/g'
sudo kubectl apply -f kube-flannel.yml

// 只有裝了網(wǎng)絡(luò)插件后k8s集群才能正常啟動(dòng)(安裝后需要等幾分鐘贮预,才能看出來(lái))
// 剛init完kubernetes是這樣的
kubectl get nodes
NAME STATUS ROLES AGE VERSION
pcno6 NotReady control-plane,master 6m3s v1.20.1

// 過(guò)了幾分鐘是這樣的
kubectl get nodes
NAME STATUS ROLES AGE VERSION?
pcno6 Ready control-plane,master 7m3s v1.20.1

//然后查看,里面的pcno6就是master
kubectl get pods -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-7f89b7bc75-78zxc 1/1 Running 0 16h 10.244.0.3 pcno6 <none> <none>
coredns-7f89b7bc75-xf7sh 1/1 Running 0 16h 10.244.0.2 pcno6 <none> <none>
etcd-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-apiserver-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-controller-manager-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-flannel-ds-hw78n 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-proxy-ntkr4 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-scheduler-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>



4契讲,安裝node機(jī)器:

照上面的步驟全部做一遍仿吞,只是把kubeadm init ,換成?kubeadm join(用init最后輸出的kubeadm join就好)

sudo kubeadm join 10.10.30.76:6443 --token 4xic6x.jhcftora8nvnlbt9 --discovery-token-ca-cert-hash sha256:d23cc3c4aba172df962ecb8735292793cb7a101965ffa71631bf50e593c31904 --ignore-preflight-errors=...
[preflight] Running pre-flight checks
?????[WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
?????[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03 [preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster:
????* Certificate signing request was sent to apiserver and a response was received.
????* The Kubelet was informed of the new secure connection details.
?Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

//然后在master機(jī)器上查看(pcno5就是node節(jié)點(diǎn))
kubectl get nodes
NAME STATUS ROLES AGE VERSION
pcno5 Ready <none> 13m v1.20.1
pcno6 Ready control-plane,master 74m v1.20.1

//再查看master的所有pod和container
kubectl get pods -n kube-system -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
coredns-7f89b7bc75-78zxc 1/1 Running 0 16h 10.244.0.3 pcno6 <none> <none>
coredns-7f89b7bc75-xf7sh 1/1 Running 0 16h 10.244.0.2 pcno6 <none> <none>
etcd-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-apiserver-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-controller-manager-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-flannel-ds-6zv79 1/1 Running 0 15h 10.10.30.75 pcno5 <none> <none>
kube-flannel-ds-hw78n 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-proxy-7nttl 1/1 Running 0 15h 10.10.30.75 pcno5 <none> <none>
kube-proxy-ntkr4 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>
kube-scheduler-pcno6 1/1 Running 0 16h 10.10.30.76 pcno6 <none> <none>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末捡偏,一起剝皮案震驚了整個(gè)濱河市唤冈,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌银伟,老刑警劉巖你虹,帶你破解...
    沈念sama閱讀 222,378評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異彤避,居然都是意外死亡傅物,警方通過(guò)查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門(mén)琉预,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)董饰,“玉大人,你說(shuō)我怎么就攤上這事圆米∽湓荩” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 168,983評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵娄帖,是天一觀(guān)的道長(zhǎng)也祠。 經(jīng)常有香客問(wèn)我,道長(zhǎng)块茁,這世上最難降的妖魔是什么齿坷? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,938評(píng)論 1 299
  • 正文 為了忘掉前任,我火速辦了婚禮数焊,結(jié)果婚禮上永淌,老公的妹妹穿的比我還像新娘。我一直安慰自己佩耳,他們只是感情好遂蛀,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,955評(píng)論 6 398
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著干厚,像睡著了一般李滴。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上蛮瞄,一...
    開(kāi)封第一講書(shū)人閱讀 52,549評(píng)論 1 312
  • 那天所坯,我揣著相機(jī)與錄音,去河邊找鬼挂捅。 笑死芹助,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的闲先。 我是一名探鬼主播状土,決...
    沈念sama閱讀 41,063評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼伺糠!你這毒婦竟也來(lái)了蒙谓?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,991評(píng)論 0 277
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤训桶,失蹤者是張志新(化名)和其女友劉穎累驮,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體渊迁,經(jīng)...
    沈念sama閱讀 46,522評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡慰照,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,604評(píng)論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了琉朽。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片毒租。...
    茶點(diǎn)故事閱讀 40,742評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖箱叁,靈堂內(nèi)的尸體忽然破棺而出墅垮,到底是詐尸還是另有隱情,我是刑警寧澤耕漱,帶...
    沈念sama閱讀 36,413評(píng)論 5 351
  • 正文 年R本政府宣布算色,位于F島的核電站,受9級(jí)特大地震影響螟够,放射性物質(zhì)發(fā)生泄漏灾梦。R本人自食惡果不足惜峡钓,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,094評(píng)論 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望若河。 院中可真熱鬧能岩,春花似錦、人聲如沸萧福。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,572評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)鲫忍。三九已至膏燕,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間悟民,已是汗流浹背坝辫。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,671評(píng)論 1 274
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留射亏,地道東北人阀溶。 一個(gè)月前我還...
    沈念sama閱讀 49,159評(píng)論 3 378
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像鸦泳,于是被迫代替她去往敵國(guó)和親银锻。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,747評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容