本篇文章是在空白虚拟机或者物理机上部署Kubernetes-v1.13.4集群
我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:
1.修改主机名
master节点:
vi /etc/hostname
master
node节点:
vi /etc/hostname
node
完成后重启
2.添加dns
vi /etc/resolv.conf
nameserver 8.8.8.8
nameserver 114.114.114.114
3.配置阿里源
mv /etc/apt/sources.list /etc/apt/sources.list
vi /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe
配置kubernetes的源
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add
vi /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
更新源:
apt-get update
4.配置对时
apt-get install -y ntpdate
ntpdate -u ntp.api.bz
5.配置apt https规则
apt-get install -y apt-transport-https
6.关闭swap
swapoff -a
vi /etc/fstab
注释掉带swap的一行
7.添加hosts
vi /etc/hosts
xxx.xxx.xxx.11 master
xxx.xxx.xxx.12 node
1.安装kubernetes(所有节点执行)
apt-get install –y kubernetes-cni=0.6.0-00
apt-get install -y kubelet=1.13.4-00 kubeadm=1.13.4-00 kubectl=1.13.4-00
注:这里的kubernetes-cni、kubelet、kubeadm、kubectl必须要指定版本安装,因为kubernetes需要依赖kubernetes-cni0.6.而自动安装kubernetes-cni,最低也是0.7版本,支持kubernetes最低为1.15版本
2.标记软件不被自动更新(所有节点执行)
apt-mark hold kubelet kubeadm kubectl
3.安装docker(所有节点执行)
apt-get install docker.io=18.06.1-0ubuntu1.2~16.04.1 -y
systemctl enable docker
4.下载镜像(所有节点执行)
mkdir /k8s
vi pull_k8s_images.sh
### 版本信息
K8S_VERSION=v1.13.4
ETCD_VERSION=3.2.24
DASHBOARD_VERSION=v1.10.1
DNS_VERSION=1.14.5
PAUSE_VERSION=3.0
### 基本组件
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:$PAUSE_VERSION
### 网络
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-sidecar-amd64:$DNS_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-kube-dns-amd64:$DNS_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-dnsmasq-nanny-amd64:$DNS_VERSION
### 前端
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION
###修改tag
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION gcr.io/kube-apiserver:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION gcr.io/kube-controller-manager:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION gcr.io/kube-scheduler:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION gcr.io/kube-proxy:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION gcr.io/etcd:$ETCD_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:$PAUSE_VERSION gcr.io/pause:$PAUSE_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-sidecar-amd64:$DNS_VERSION gcr.io/k8s-dns-sidecar:$DNS_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-kube-dns-amd64:$DNS_VERSION gcr.io/k8s-dns-kube-dns:$DNS_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-dnsmasq-nanny-amd64:$DNS_VERSION gcr.io/k8s-dns-dnsmasq-nanny:$DNS_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION gcr.io/kubernetes-dashboard:$DASHBOARD_VERSION
## 删除镜像
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver-amd64:$K8S_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager-amd64:$K8S_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler-amd64:$K8S_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy-amd64:$K8S_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/etcd-amd64:$ETCD_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/pause-amd64:$PAUSE_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-sidecar-amd64:$DNS_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-kube-dns-amd64:$DNS_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-dnsmasq-nanny-amd64:$DNS_VERSION
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:$DASHBOARD_VERSION
sh pull_k8s_images.sh
5.初始化master节点(master节点执行)
kubeadm init --kubernetes-version=v1.13.4 --token-ttl=0 --pod-network-cidr=192.168.0.0/16
注:此命令执行成功后会输出successfully和一段文字加编码请全句保存好,添加节点时使用
6.执行本地配置(master节点执行)
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
将以上文件复制到node节点
7.安装网络插件(master节点执行)
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
8.node节点加入集群(node节点执行)
kubeadm join masterIP:6443 --token oicybi.8cyp7zbwynta0wg0 --discovery-token-ca-cert-hash sha256:30e07ca44d2b9740247c90e94de83686c84a6b2ea5fb4c2782ff0xxxxxx
注:此处内容为初始化master节点时的输出内容
9.检测部署情况
kubectl get nodes
检查所有节点状态为ready,版本为v1.13.4
kubectl get pod –all-namespaces
检查所有pod状态为running