k8s kubeadm方式安装

原创
2020/10/08 23:28
阅读数 154

关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

关闭 selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时

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

主机名
hostnamectl set-hostname <hostname>

#master 节点执行
cat >> /etc/hosts << EOF
192.168.1.100 k8smaster
192.168.1.101 k8snode1
192.168.1.102 k8snode2
EOF


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

yum install ntpdate -y

ntpdate time.windows.com

安装docker
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum -y install docker-ce-18.06.1.ce-3.el7

开机启动docker
systemctl enable docker && systemctl start docker

docker --version

配置阿里云镜像
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF

重启后阿里云生效
systemctl restart docker

添加阿里云yum源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

安装kubelet kubeadm kubectl 指定的稳定版安装,不加为最新版本的
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0

systemctl enable kubelet

在master里面执行,地址为master的ip地址
kubeadm init --apiserver-advertise-address=192.168.1.100 --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


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

然后
kubectl get nodes

会出现
NAME        STATUS     ROLES    AGE     VERSION
k8smaster   NotReady   master   6m10s   v1.18.0

然后安装pod网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

安装fannel  

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

报错:The connection to the server raw.githubusercontent.com was refused - did you specify the right host or port?  

原因:外网不可访问

解决办法:

# 在https://www.ipaddress.com/查询raw.githubusercontent.com的真实IP。
sudo vim /etc/hosts
199.232.28.133 raw.githubusercontent.com

向集群中添加新节点,在node节点执行
kubeadm join 192.168.1.100:6443 --token 39ys82.v727ax2x7n508ac1 --discovery-token-ca-cert-hash sha256:2ac7fe651b929afd0552023eb02e1f8eeba7bd4140164a639a251a01b9de5a9c

kubectl get pods -n kube-system

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部