溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

kubernates cluster搭建的過程

發(fā)布時(shí)間:2021-08-31 10:44:41 來源:億速云 閱讀:120 作者:chen 欄目:云計(jì)算

這篇文章主要講解了“kubernates cluster搭建的過程”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“kubernates cluster搭建的過程”吧!

如果選擇Ubuntu,則建議選擇16.04.6版本。因?yàn)閲鴥?nèi)各大鏡像上都有針對該版本的k8s,且廣泛應(yīng)用。

安裝環(huán)境:3臺(tái)Ubuntu 16.04

Step 1: Install & Enable Docker on both the nodes

# Install Docker CE

## Set up the repository:

### Install packages to allow apt to use a repository over HTTPS

apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common

### Add Docker’s official GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

### Add Docker apt repository.

add-apt-repository \

  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \

  $( lsb_release -cs ) \

  stable"

## Install Docker CE.

apt-get update && apt-get install docker-ce = 18 .06.2~ce~3-0~ubuntu

# Setup daemon.

cat > /etc/docker/daemon.json <<EOF

{

  "exec-opts": ["native.cgroupdriver=systemd"],

  "log-driver": "json-file",

  "log-opts": {

    "max-size": "100m"

  },

  "storage-driver": "overlay2"

}

EOF

mkdir -p /etc/systemd/system/docker.service.d

# Restart docker.

systemctl daemon-reload

systemctl restart docker

systemctl enable docker

docker verision

Step 2: Add the Kubernetes signing key on both the nodes

sudo apt install curl

curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg  | sudo apt-key add

sudo apt-get update && sudo apt-get install -y apt-transport-https

Step 3: Add Xenial Kubernetes Repository on both the nodes

sudo apt-add-repository " deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main"

Step 4: Install Kubeadm

apt-get update

apt-get install -y kubelet kubeadm kubectl

apt-mark hold kubelet kubeadm kubectl

kubeadm version

Kubernetes Deployment

Step 1: Disable swap memory (if running) on both the nodes

sudo swapoff -a

Step 2: Give Unique hostnames to each node

sudo hostnamectl set-hostname master-node-vm1

sudo hostnamectl set-hostname slave-node-vm2  

sudo hostnamectl set-hostname slave-node-vm3  

Step3: deploy required docker images for kubernates to each node

kubeadm config images list  |  sed  -e  's/^/docker pull /g'  -e  's#k8s.gcr.io#docker.io/mirrorgooglecontainers#g'  |  sh -x

docker images  |  grep  mirrorgooglecontainers  |  awk  '{print "docker tag ",  $1  ":"  $2  ,  $1  ":"  $2  }'  |  sed  -e  's#mirrorgooglecontainers#k8s.gcr.io#2'  |  sh -x

docker images  |  grep  mirrorgooglecontainers  |  awk  '{print "docker rmi ",  $1  ":"  $2  }'  |  sh -x

docker pull coredns/coredns:1.3.1

docker tag coredns/coredns:1.3.1  k8s.gcr.io/coredns:1.3.1

docker rmi coredns/coredns:1.3.1

kubernates cluster搭建的過程

    mkdir -p $HOME/.kube  

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

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

Step4: Initialize Kubernetes on the master node

kubectl apply -f  https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

sudo kubeadm init --kubernetes-version=v1.14.3 --pod-network-cidr=10.244.0.0/16  

####check all required containers is running:  

kubectl get pods --all-namespaces

kubernates cluster搭建的過程  

Step5: Join Kubernetes on the slave node

after initialize the master node you will see below info

kubernates cluster搭建的過程  

copy the last sentence to slave node to join master node:

kubeadm join 192.168.7.86:6443 --token uedhm1.s9yo055ckphqdw16 --discovery-token-ca-cert-hash sha256:d96d1d924df350fe361082afe1c981c8fb6d2361aa6d1811c8d628b93b90e61d  

Step6: Check all nodes on master node

kubectl get nodes

kubernates cluster搭建的過程

感謝各位的閱讀,以上就是“kubernates cluster搭建的過程”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對kubernates cluster搭建的過程這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI