Kubernetes 安裝(備忘)

準(zhǔn)備工作

體驗(yàn)下,準(zhǔn)備了3臺(tái)機(jī)器,正式應(yīng)該最少4臺(tái),2臺(tái)master,2臺(tái)node

1. 修改配置幾臺(tái) host

vim /etc/hosts

(內(nèi)網(wǎng)IP)

172.27.154.95   master01
172.27.154.96   node01
172.27.154.97   node02

關(guān)閉防火墻

(并未設(shè)置孵运,同賬號(hào)內(nèi)網(wǎng))

systemctl stop firewalld
systemctl disable firewalld

關(guān)閉 Swap

swapoff -a # 臨時(shí)關(guān)閉
sed -ri 's/.*swap.*/#&/' /etc/fstab  #永久關(guān)閉

關(guān)閉 SELinux

# 臨時(shí)禁用selinux

# 永久關(guān)閉 修改/etc/sysconfig/selinux文件設(shè)置
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux

# 這里按回車搀绣,下面是第二條命令
setenforce 0

配置轉(zhuǎn)發(fā)參數(shù)

lsmod | grep br_netfilter #確認(rèn)是否有加載此模塊
sudo modprobe br_netfilter  #沒有的話可以先加載


cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sudo sysctl --system

正式安裝

Docker 安裝

官方

https://docs.docker.com/engine/install/centos/

阿里云

https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.2fee1b11WmG5YE

配置鏡像加速器

https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

您可以通過修改daemon配置文件/etc/docker/daemon.json來使用加速器

sudo mkdir -p /etc/docker 

sudo tee /etc/docker/daemon.json <<-'EOF’ 
{ 
    "registry-mirrors": ["https://***.mirror.aliyuncs.com”] 
} 
EOF 

sudo systemctl daemon-reload 

sudo systemctl restart docker

vim /etc/docker/daemon.json

{
    "registry-mirrors": [
        "https://***.mirror.aliyuncs.com"
    ],
    "exec-opts": [
        "native.cgroupdriver=systemd"
    ]
}

systemctl restart docker.service


安裝 Kubernetes

https://developer.aliyun.com/mirror/kubernetes?spm=a2c6h.13651102.0.0.2fee1b11WmG5YE

kubeadm init --image-repository=registry.aliyuncs.com/google_containers

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf\nnet.bridge.bridge-nf-call-ip6tables = 1\nnet.bridge.bridge-nf-call-iptables = 1\nEOF

報(bào)錯(cuò):

error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR ImagePull]: failed to pull image registry.aliyuncs.com/google_containers/coredns:v1.8.4: output: Error response from daemon: manifest for registry.aliyuncs.com/google_containers/coredns:v1.8.4 not found: manifest unknown: manifest unknown
, error: exit status 1

kubeadm reset

docker pull coredns/coredns
docker tag coredns/coredns:latest registry.aliyuncs.com/google_containers/coredns:v1.8.4

kubeadm init --image-repository=registry.aliyuncs.com/google_containers

mkdir -p $HOME/.kube

sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

sudo chown $(id -u):$(id -g) $HOME/.kube/config

systemctl status kubelet

master 查看節(jié)點(diǎn)檢查token是否有效

kubeadm token list

生成新的token和命令。然后在node重新執(zhí)行

kubeadm token create --print-join-command

Node節(jié)點(diǎn)

join報(bào)錯(cuò):

[preflight] Running pre-flight checks
        [WARNING Hostname]: hostname "gkwc" could not be reached
        [WARNING Hostname]: hostname "gkwc": lookup gkwc on 100.100.2.138:53: no such host
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR FileAvailable--etc-kubernetes-kubelet.conf]: /etc/kubernetes/kubelet.conf already exists
        [ERROR Port-10250]: Port 10250 is in use
        [ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

kubeadm reset

kubeadm join 172.23.103.13:6443 --token oekgxb.kiqqr7a6egz9o39s \
        --discovery-token-ca-cert-hash sha256:ef965eae9b886af2f538800d4e449572dc79330d1f85bc50219a33ec972e1e6f

輸出:

[preflight] Running pre-flight checks
        [WARNING Hostname]: hostname "gkwc" could not be reached
        [WARNING Hostname]: hostname "gkwc": lookup gkwc on 100.100.2.138:53: no such host
[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.

安裝calico網(wǎng)絡(luò):

kubectl apply -f "https://docs.projectcalico.org/manifests/calico.yaml"
  
kubectl get nodes
  
kubectl get pods --all-namespaces

安裝CNI網(wǎng)絡(luò)插件:

kubectl apply -f "https://docs.projectcalico.org/manifests/calico.yaml"

部署 Dashboard UI

https://kubernetes.io/zh/docs/tasks/access-application-cluster/web-ui-dashboard/

https://github.com/kubernetes/dashboard

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml 

本地端口映射服務(wù)器8001端口:

ssh -L localhost:8001:localhost:8001 root@master公網(wǎng)IP
然后本地打開
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.
查看token

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

此時(shí)能登錄進(jìn)入:


image.png

但頁(yè)面都是空的,并有錯(cuò)誤
出現(xiàn)上述問題的原因是因?yàn)槟乎澹琸ubernetes-dashboard 這個(gè)賬戶的角色權(quán)限不夠

新建 dashboard-adminuser.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard


---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

然后:
kubectl apply -f dashboard-adminuser.yaml
再次查看 admin-user 的 token

kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')

退出登錄,然后用新的token登錄:

image.png
image.png
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末怨愤,一起剝皮案震驚了整個(gè)濱河市派敷,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌憔四,老刑警劉巖膀息,帶你破解...
    沈念sama閱讀 211,042評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異了赵,居然都是意外死亡潜支,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評(píng)論 2 384
  • 文/潘曉璐 我一進(jìn)店門柿汛,熙熙樓的掌柜王于貴愁眉苦臉地迎上來冗酿,“玉大人,你說我怎么就攤上這事络断〔锰妫” “怎么了?”我有些...
    開封第一講書人閱讀 156,674評(píng)論 0 345
  • 文/不壞的土叔 我叫張陵貌笨,是天一觀的道長(zhǎng)弱判。 經(jīng)常有香客問我,道長(zhǎng)锥惋,這世上最難降的妖魔是什么昌腰? 我笑而不...
    開封第一講書人閱讀 56,340評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮膀跌,結(jié)果婚禮上遭商,老公的妹妹穿的比我還像新娘。我一直安慰自己捅伤,他們只是感情好劫流,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,404評(píng)論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般祠汇。 火紅的嫁衣襯著肌膚如雪仍秤。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,749評(píng)論 1 289
  • 那天座哩,我揣著相機(jī)與錄音徒扶,去河邊找鬼。 笑死根穷,一個(gè)胖子當(dāng)著我的面吹牛姜骡,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播屿良,決...
    沈念sama閱讀 38,902評(píng)論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼圈澈,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了尘惧?” 一聲冷哼從身側(cè)響起康栈,我...
    開封第一講書人閱讀 37,662評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎喷橙,沒想到半個(gè)月后啥么,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,110評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡贰逾,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,451評(píng)論 2 325
  • 正文 我和宋清朗相戀三年悬荣,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片疙剑。...
    茶點(diǎn)故事閱讀 38,577評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡氯迂,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出言缤,到底是詐尸還是另有隱情嚼蚀,我是刑警寧澤,帶...
    沈念sama閱讀 34,258評(píng)論 4 328
  • 正文 年R本政府宣布管挟,位于F島的核電站轿曙,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏僻孝。R本人自食惡果不足惜拳芙,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,848評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望皮璧。 院中可真熱鬧,春花似錦分飞、人聲如沸悴务。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)讯檐。三九已至羡疗,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間别洪,已是汗流浹背叨恨。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評(píng)論 1 264
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留挖垛,地道東北人痒钝。 一個(gè)月前我還...
    沈念sama閱讀 46,271評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像痢毒,于是被迫代替她去往敵國(guó)和親送矩。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,452評(píng)論 2 348

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