返回目录
1.设置系统参数,到5之前,每个k8s服务器都要执行(我这里共4个,200~203)
cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
2.配置yum源
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
3.安装kubeadm&kubelet&kubectl
K8s对应docker的版本
yum install -y kubeadm-1.17.7-0 kubelet-1.17.7-0 kubectl-1.17.7-0
4.docker和k8s设置同一个cgroup
docker:
vi /etc/docker/daemon.json
增加:
“exec-opts”: [“native.cgroupdriver=systemd”]
systemctl restart docker
kubelet:如果发现输出directory not exist,也说明是没问题的
sed -i “s/cgroup-driver=systemd/cgroup-driver=cgroupfs/g” /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
systemctl enable kubelet
systemctl start kubelet
5.初始化master,该部分仅master执行
kubeadm reset
echo “1” > /proc/sys/net/ipv4/ip_forward
应该直接执行此命令,同时会下载docker image
kubeadm init --kubernetes-version=1.17.7 --apiserver-advertise-address=192.168.50.200 --pod-network-cidr=10.244.0.0/16
但是国外网站把我们屏蔽了,只能使用替代方法:
替换方式:
docker pull mirrorgcrio/kube-apiserver:v1.17.7
docker pull mirrorgcrio/kube-controller-manager:v1.17.7
docker pull mirrorgcrio/kube-scheduler:v1.17.7
docker pull mirrorgcrio/kube-proxy:v1.17.7
docker pull mirrorgcrio/pause:3.1
docker pull mirrorgcrio/etcd:3.4.3-0
docker pull mirrorgcrio/coredns:1.6.5
docker tag mirrorgcrio/kube-proxy:v1.17.7 k8s.gcr.io/kube-proxy:v1.17.7
docker tag mirrorgcrio/kube-scheduler:v1.17.7 k8s.gcr.io/kube-scheduler:v1.17.7
docker tag mirrorgcrio/kube-apiserver:v1.17.7 k8s.gcr.io/kube-apiserver:v1.17.7
docker tag mirrorgcrio/kube-controller-manager:v1.17.7 k8s.gcr.io/kube-controller-manager:v1.17.7
docker tag mirrorgcrio/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag mirrorgcrio/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgcrio/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5
再执行:
kubeadm init --kubernetes-version=1.17.7 --apiserver-advertise-address=192.168.50.200 --pod-network-cidr=10.244.0.0/16
注意保存如下信息:
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (id−u):(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 192.168.50.200:6443 --token e5l733.6nojmccfe3qtht7x
–discovery-token-ca-cert-hash sha256:11a31258153d1ed7a2df8ad763ac47e1aba894294292c3b73f5eea419fe54d27
根据日志提示执行
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (id−u):(id -g) $HOME/.kube/config
kubectl get pods -n kube-system 【查看kube-system的pods】
kubectl get pods --all-namespaces 【查看所有pods】
健康检查
curl -k https://localhost:6443/healthz
部署calico网络插件:查询需要的镜像版本,我这里先用calico,其他的网络插件以后再看
curl https://docs.projectcalico.org/v3.9/manifests/calico.yaml | grep image
根据镜像版本拉去镜像
docker pull calico/cni:v3.9.6
docker pull calico/pod2daemon-flexvol:v3.9.6
docker pull calico/node:v3.9.6
docker pull calico/kube-controllers:v3.9.6
在k8s中安装calico
yum install -y wget
wget https://docs.projectcalico.org/v3.9/manifests/calico.yaml
kubectl apply -f calico.yaml
确认一下calico是否安装成功
kubectl get pods --all-namespaces -w 【实时查看所有的Pods】
6.slave处理,如下部分每个slave都要执行
这个命令就是前面master安装成功后生成的命令。
kubeadm join 192.168.50.200:6443 --token e5l733.6nojmccfe3qtht7x
–discovery-token-ca-cert-hash sha256:11a31258153d1ed7a2df8ad763ac47e1aba894294292c3b73f5eea419fe54d27
systemctl restart docker
systemctl restart kubelet