K8S 1.14安装

Mon May 27, 2019

300 Words|Read in about 2 Min
Tags:

手工安装kubernetes1.14集群
事前准备:
1.关闭所有节点的swap
2.关闭防火墙
3.如果存在selinux请关闭

1.所有节点安装docker、kubelet、kubeadm、kubectl

curl -fsSL https://get.docker.com | bash -s docker –mirror Aliyun
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 kubelet kubeadm kubectl

2.在master和node节点拉取海外docker镜像

列出所需要img

kubeadm config images list:
k8s.gcr.io/kube-apiserver:v1.14.0
k8s.gcr.io/kube-controller-manager:v1.14.0
k8s.gcr.io/kube-scheduler:v1.14.0
k8s.gcr.io/kube-proxy:v1.14.0
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1

3.master上初始化

kubeadm init

初始化成功后你会看见如下提示

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 $(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.0.20:6443 –token 8sio7q.g6cj9m15c0ev3d9b \
–discovery-token-ca-cert-hash sha256:81fc89c762536cadc9580278bd12fe14933ead5d9bdf5b5b1a9c07f0a3084958

若初始化失败,执行以下命令清理一些可能存在的网络问题,然后重新初始化:

kubeadm reset
ifconfig cni0 down
ip link delete cni0
ifconfig flannel.1 down
ip link delete flannel.1
rm -rf /var/lib/cni/

4.node加入集群

配置全局代理

cat <<EOF >  ~/.bashrc
export http_proxy=http://username:password@ip:port
export https_proxy=http://username:password@ip:port
export no_proxy=localhost,127.0.0.1,<your-server-ip>(本机ip地址)
EOF
source ~/.bashrc	

#配置docker代理,拉谷歌镜像要用到:
mkdir -p /etc/systemd/system/docker.service.d/
cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=http://username:password@ip:port" "HTTPS_PROXY=http://username:password@ip:port" "NO_PROXY=localhost,127.0.0.1,<your-server-ip>"
EOF
systemctl daemon-reload
systemctl restart docker
kubeadm join 192.168.0.20:6443 –token 8sio7q.g6cj9m15c0ev3d9b \
–discovery-token-ca-cert-hash sha256:81fc89c762536cadc9580278bd12fe14933ead5d9bdf5b5b1a9c07f0a3084958

如果加入失败,需要配置docker代理科学上网。
再如果失败可以重置节点
kubeadm reset

即可

5.coredns可能运行有问题,是因为网络还不是覆盖网络

需要安装

https://docs.projectcalico.org/v3.6/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

修改里面cidr方面的参数然后创建应用 @master上

6.安装完成

NAME STATUS ROLES AGE VERSION
node20 Ready master 9d v1.14.0
node21 Ready <none> 9d v1.14.0
node22 Ready <none> 7d22h v1.14.0

7.kubeadm reset干了些什么

systemctl stop kubelet;
docker rm -f -v $(docker ps -q);
find /var/lib/kubelet | xargs -n 1 findmnt -n -t tmpfs -o TARGET -T | uniq | xargs -r umount -v;
rm -r -f /etc/kubernetes /var/lib/kubelet /var/lib/etcd;

See Also

Mon May 27, 2019

300 Words|Read in about 2 Min
Tags: