ubuntu18中快速部署一套k8s集群
你有试过一小时快速手动、部署k8s集群么?
这里选择ubuntu18,和16不一样的是,18使用了netplan模块,所以和16修改网卡的方式不一样。
修改网卡
cd /etc/netplan/
vi 01-netcfg.yam
vi 50-cloud-init.yaml(或者是别的名字)
测试网络是否通
reboot
ping www.baidu.com
ifconfig
我个人把我的vim设置成了高亮
cd
vim .vimrc
创建了一个专属的k8s文件夹 并把指定的docker包上传上去。可以使用远程工具上传,也可以使用rz
mkdir workingk8s
mv /home/controller/docker-ce_18.06.1~ce~3-
apt-get install -y libltdl7(安装依赖)
docker的安装 docker的使用
dpkg -i docker-ce_18.06.1\~ce\~3-0\~ubuntu_amd64.deb
systemctl start docker
sudo mkdir -p /etc/docker
(因为docker的源是国外的,把他设置成国内的)
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://2er420eq.mirror.aliyuncs.com"] } EOF
systemctl enable docker
systemctl daemon-reload
systemctl restart docker
docker version
docker image
docker pull hello-world
docker run helloworld:latest
docker pull redis
docker run -it--rm redis /bin/bash
设置时间同步
apt install ntpdate ntpsec-ntpdate
apt install ntpdate
apt install ntpsec-ntpdate
ntpdate time.windows.com
配置k8s源
touch /etc/apt/sources.list.d/kubernetes.list
chmod 666 /etc/apt/sources.list.d/kubernetes.list
vi /etc/apt/sources.list.d/kubernetes.list
里面写
deb http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
apt update
必然会出现以下校验问题
Err:1 http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial
InRelease The following signatures couldn’t be verified because
the public key is not available: NO_PUBKEY 6A030B21BA07F4FB Could
not wait for server fd - select (11: Resource temporarily unavailable)
[IP: 202.141.176.110 443] W: GPG error:
http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial InRelease:
The following signatures couldn’t be verified because the public key
is not available: NO_PUBKEY 6A030B21BA07F4FB E: The repository
‘http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial
InRelease’ is not signed. N: Updating from such a repository can’t be
done securely, and is therefore disabled by default.***
gpg --keyserver keyserver.ubuntu.com --recv-keys 8B57C5C2836F4BEB
gpg --export --armor 8B57C5C2836F4BEB | sudo apt-key add -
sudo apt update
关闭防火墙 关闭selinux 关闭swap分区 设置内核参数 设置主机名 设置域名解析
sudo ufw disable
sudo swapoff -a
sudo sed -i 's/.*swap.*/#&/' /etc/fstab
sudo apt install -y selinux-utils
setenforce 0
reboot
设置内核参数
vi /etc/sysctl.d/k8s.conf
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
/etc/sysctl.d/k8s.conf 里面写
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness = 0
设置主机名
vi /etc/hostname
master
域名解析
vim /etc/hosts
xx.xx.xx.xx master
xx.xx.xx.xx work1
xx.xx.xx.xx work2
apt update && apt-get install -y kubelet=1.13.1-00 kubernetes-cni=0.6.0-00 kubeadm=1.13.1-00 kubectl=1.13.1-00
systemctl enable kubelet && systemctl start kubelet
kubeadm config print init-defaults ClusterConfiguration > kubeadm.conf
vi kubeadm.conf
修改仓库imageRepository:registry.cn-beijing.aliyuncs.com/imcto
修改kubernetes版本 kubernetesVersion: v1.13.0改为
kubernetesVersion: v1.13.1
只装好了最重要的组件。其中一些关键的组件镜像也需要拉取。
kubeadm config images list --config kubeadm.conf
kubeadm config images pull --config ./kubeadm.conf
初始化在kubeadm.conf中执行此命令
kubeadm init --config ./kubeadm.conf
初始化成功。然后把最后token和hash值记下来,建议存到本地
依照提示创建文件。下载flannel插件
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
wget https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
kubectl get pod -n kube-system
kubectl get nodes
之后别的节点就可以加入这个k8s集群了
更多推荐
所有评论(0)