标签:没有 目录 swa 命令 host lis efault 更新 star
实验环境介绍计算机名 | IP地址 | 操作系统及内核版本 |
---|---|---|
k8s-master.mfyxw.com | 192.168.80.100 | CentOS7.6内核推荐:4.4+及以上 |
k8s-node1.mfyxw.com | 192.168.80.110 | CentOS7.6内核推荐:4.4+及以上 |
k8s-node2.mfyxw.com | 192.168.80.120 | CentOS7.6内核推荐:4.4+及以上 |
K8S_VERSION=v1.16.2
ETCD_VERSION=3.3.15-0
PAUSE_VERSION=3.1
DNS_VERSION=1.6.2
FLANNEL_VERSION=v0.11.0-amd64
#pull镜像到本地
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:$ETCD_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION
docker pull quay-mirror.qiniu.com/coreos/flannel:$FLANNEL_VERSION
#修改tag,因k8s默认找镜像的时候,会去k8s.gcr.io/coredns:XXXXX查找
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:$K8S_VERSION k8s.gcr.io/kube-apiserver:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:$K8S_VERSION k8s.gcr.io/kube-scheduler:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:$K8S_VERSION k8s.gcr.io/kube-controller-manager:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:$ETCD_VERSION k8s.gcr.io/etcd:$ETCD_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:$K8S_VERSION k8s.gcr.io/kube-proxy:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION k8s.gcr.io/pause:$PAUSE_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION k8s.gcr.io/coredns:$DNS_VERSION
docker tag quay-mirror.qiniu.com/coreos/flannel:$FLANNEL_VERSION quay.io/coreos/flannel:$FLANNEL_VERSION
给k8s-master.sh脚本添加执行权限
chmod 755 k8s-master.sh
./k8s-master.sh
12.查询下是否镜像下载完成
命令:
docker images -a
13.在各node节点上新建一个k8s-node.sh脚本文件,
vi /root/k8s-node.sh
添加如下内容
#!/bin/bash
K8S_VERSION=v1.16.2
PAUSE_VERSION=3.1
DNS_VERSION=1.6.2
FLANNEL_VERSION=v0.11.0-amd64
#pull镜像到本地
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:$K8S_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION
docker pull quay-mirror.qiniu.com/coreos/flannel:$FLANNEL_VERSION
#修改tag
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:$K8S_VERSION k8s.gcr.io/kube-proxy:$K8S_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:$PAUSE_VERSION k8s.gcr.io/pause:$PAUSE_VERSION
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:$DNS_VERSION k8s.gcr.io/coredns:$DNS_VERSION
docker tag quay-mirror.qiniu.com/coreos/flannel:$FLANNEL_VERSION quay.io/coreos/flannel:$FLANNEL_VERSION
给/root/k8s-node.sh脚本添加可执行权限并执行脚本
命令
chmod 755 /root/k8s-node.sh
14.在各node节点上查看下载的镜像
.
15.在各节点上,把swap交换空间给关闭
命令
swapoff -a //立即生效
编辑配置文件使开机自动不开启交换空间
vi /etc/fstab在swap交换分区前面添加#号注释
16.在k8s-master节点上使用kubeadm初始化(kubernetes版本使用1.16.2是因为在下载镜像下载了此镜像版本)
命令
kubeadm init --kubernetes-version=1.16.2 --pod-network-cidr 10.244.0.0/16 --service-cidr 10.96.0.0/12
注意:kubernetes要求最低需要双核CPU(master和node节点都需要双核)
节点k8s-master成功完成了初始化
kubeadm join 192.168.80.100:6443 --token tlxsrq.7cilafwfvxh09k7z \
--discovery-token-ca-cert-hash sha256:8145748aa23b2563580c39065dde084863b59202c209a4566ac2df377b9f66b3
因为是做实验,故使用root用户来运行,不切换到普通用户运行如下命令
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
17.查看pod节点和node节点
命令:
kubectl get pods -n kube-system
kubectl get nodes
在查看node上显示NotReady(未就绪状态)是由于flannel没有启动
在flannel的github(https://github.com/coreos/flannel)上说到,kubernetes1.7+以上需要使用如下命令来运行flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
flannel已经运行,再次查看nodes和pods -n kube-system
18.在各node节点上运行如下命令加入集群
命令:
kubeadm join 192.168.80.100:6443 --token tlxsrq.7cilafwfvxh09k7z \
--discovery-token-ca-cert-hash sha256:8145748aa23b2563580c39065dde084863b59202c209a4566ac2df377b9f66b3
19.再次在k8s-master节点上运行如下命令查询集群所有节点情况
命令:
kubectl get nodes
标签:没有 目录 swa 命令 host lis efault 更新 star
原文地址:https://blog.51cto.com/7309656/2446761