美文网首页
ubuntu-kubeadm部署8s

ubuntu-kubeadm部署8s

作者: 会倒立的香飘飘 | 来源:发表于2021-03-03 15:32 被阅读0次

ubuntu 部署k8s

准备环境工作

准备节点

master 10.0.0.88
node01 10.0.0.89
node02 10.0.0.90

关闭防火墙

systemctl stop ufw
ufw disable

关闭swap

永久关闭:
vim /etc/fstab
临时关闭:
swapoff -a

添加hosts

cat >/etc/hosts <<EOF
10.0.0.88 master
10.0.0.89 node1
10.0.0.90 node2
EOF

将桥接的IPv4流量传递到iptables的链

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

生效:
sysctl --system 

时间同步

apt-get  install ntpdate -y
ntpdate time.windows.com

安装docker

安装必要的一些系统工具

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

安装GPG证书

curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

写入软件源信息

sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

更新并安装Docker-CE

apt-get -y update
apt-get -y install docker-ce
systemctl enable docker && systemctl start docker

安装指定版本的Docker-CE:

查找Docker-CE的版本:

apt-cache madison docker-ce
   docker-ce | 5:20.10.4~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
   docker-ce | 5:19.03.8~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
   docker-ce | 5:18.09.3~3-0~ubuntu-bionic | https://mirrors.aliyun.com/docker-ce/linux/ubuntu bionic/stable amd64 Packages
   安装指定版本的Docker-CE: (VERSION例如上面的17.03.1~ce-0~ubuntu-xenial)
   apt-get -y install docker-ce=[VERSION]

配置镜像加速

mkdir /etc/docker/ -p 
cat >/etc/docker/daemon.json << EOF
{"registry-mirrors":["https://b9pmyelo.mirror.aliyuncs.com"]}
EOF
systemctl restart docker

安装kubeadm,kubectl,kubelet

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
   
apt-get update
apt-get install  -y kubectl=1.18.0-00 kubeadm=1.18.0-00 kubelet=1.18.0-00
systemctl enable kubelet

部署k8s-master初始化节点

10.0.0.88上执行

kubeadm init \
--apiserver-advertise-address=10.0.0.88 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16

初始化是遇到报错:


image.png

解决:在这个文件里添加下面这

[root@test2 ~]# vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --fail-swap-on=false"

然后重启kubeadm

kubeadm reset

重启后重新执行初始化命令就会出实话成功,

创建k8s配置文件

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

node节点加入集群

kubeadm join 10.0.0.88:6443 --token a981wy.u8weze9n88o9ac6v \
    --discovery-token-ca-cert-hash sha256:40cf331eaa40eb82bb9bae03796ee1445ec1a14acd70d0730fecb8e323c8a5e8

安装补全命令工具,

apt-get install bash-completion -y
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
kubectl completion bash >/etc/bash_completion.d/kubectl

部署flannel网络

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

查看节点

root@master:~# kubectl get node
NAME     STATUS   ROLES    AGE     VERSION
master   Ready    master   4h22m   v1.18.0
node01   Ready    <none>   4h19m   v1.18.0
node02   Ready    <none>   4h21m   v1.18.0

相关文章

网友评论

      本文标题:ubuntu-kubeadm部署8s

      本文链接:https://www.haomeiwen.com/subject/hhrqqltx.html