kubernates cluster搭建的过程

发布时间:2021-08-31 10:44:41 作者:chen
来源:亿速云 阅读:125

这篇文章主要讲解了“kubernates cluster搭建的过程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“kubernates cluster搭建的过程”吧!

如果选择Ubuntu,则建议选择16.04.6版本。因为国内各大镜像上都有针对该版本的k8s,且广泛应用。

安装环境:3台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搭建的过程”的内容了,经过本文的学习后,相信大家对kubernates cluster搭建的过程这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

推荐阅读:
  1. 基于redis-cluster搭建redis高可用集群的方法
  2. MYSQL 8 Innodb cluster mysqlsh安装详细过程及周边是怎样的

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

kubernates

上一篇:安装好JDK之后为什么需要去配置path环境变量

下一篇:kubernetes证书过期怎么处理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》