(脚本在文末自行查找)
安装docker:
镜像加速:
安装相 kubeadm 命令
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
cat /etc/apt/sources.list.d/kubernetes.list
apt-get install -y kubelet kubeadm kubectl
hostnamectl set-hostname master1
kubeadm --help
kubeadm version
apt-cache madison kubeadm kubectl
apt install kubeadm=1.15.3-00 kubelet=1.15.3-00 kubectl=1.15.3-00
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
获取镜像::
vim images-docker.sh
#!/bin/sh
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
#docker images
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
初始化 master:
# kubeadm init --apiserver-advertise-address=192.168.37.71 --apiserver-bind-port=6443 --kubernetes-version=v1.15.4 --pod-network-cidr=10.10.0.0/16 --service-cidr=10.20.0.0/16 --service-dns-domain=linux37.local --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --ignore-preflight-errors=swap --token-ttl=0
执行结果:
(kubeadm join 192.168.37.71:6443 --token ezgy4s.t1ejretokihii8qo \
--discovery-token-ca-cert-hash sha256:311e122584527cbb948df2d2d6926182a26e7a1facd24cbcad9305f88ddb58f9)
- 1.
- 2.
- 3.
- 4.
- 5.
网络插件 flannel:
https://github.com/coreos/flannel/
node:节点
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 install kubeadm=1.15.3-00 kubelet=1.15.3-00 kubectl=1.15.3-00
kubeadm join 192.168.37.71:6443 --token ezgy4s.t1ejretokihii8qo \
--discovery-token-ca-cert-hash sha256:311e122584527cbb948df2d2d6926182a26e7a1facd24cbcad9305f88ddb58f9
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
Node 节点会自动加入到 master 节点,下载镜像并启动 flannel,直到在 master
看到 node 处于 Ready 状态。
k8s 创建容器并测试:
创建测试容器,测试网络连接:
kubeadm 升级 k8s 集群:
升级 k8s 集群必须 先升级 kubeadm 版本到目的 k8s 版本,才完成k8s升级。
验证当 k8s 前版本:
# kubeadm version
安装指定版本 kubeadm:
apt-cache madison kubeadm
apt install kubelet=1.15.4-00 kubectl=1.15.4-00 kubeadm=1.15.4-00
kubeadm version
kubeadm 升级命令使用帮助:
# kubeadm upgrade --help
升级计划:
# kubeadm upgrade plan
开始升级:
# kubeadm upgrade apply v1.15.4
# 成功提示SUCCESS! Your cluster was upgraded to "v1.15.4". Enjoy!
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
验证当前版本信息:
vim docker.sh
# step 1: 安装必要的一些系统工具
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
# step 2: 安装GPG证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
# Step 3: 写入软件源信息
sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
# Step 4: 更新并安装 Docker-CE
sudo apt-get -y update
#安装docker-18.9
apt install -y docker-ce=5:18.09.9~3-0~ubuntu-bionic docker-ce-cli=5:18.09.9~3-0~ubuntu-bionic
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
vim docker-pull-k.sh
#!/bin/sh
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.3
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.