我的机器配置:

IP地址

节点角色

CPU

Memory

Hostname

磁盘

192.168.25.150

master

>=2c

>=2G

master

sda、sdb

192.168.25.151

worker

>=2c

>=2G

node1

sda、sdb

192.168.25.152

worker

>=2c

>=2G

node2

sda、sdb

PS:机器内存必须大于2G  否则报错

一、每个节点先执行公共脚本

每个节点先设置名称

hostnamectl set-hostname master

下面是一键脚本(注意hosts里面要写每个node的ip)

可以写到一个文件里面批量执行

cat <<EOF >>/etc/hosts

192.168.25.150 master

192.168.25.151 node1

192.168.25.152 node2

EOF
systemctl stop firewalld

systemctl disable firewalld

setenforce 0

sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

swapoff -a

sed -i 's/.*swap.*/#&/' /etc/fstab
cat > /etc/sysctl.d/k8s.conf <<EOF

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

EOF

sysctl --system

yum install -y wget

mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo

wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo

yum clean all && yum makecache
cat <<EOF > /etc/yum.repos.d/kubernetes.repo

[kubernetes]

name=Kubernetes

baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/

enabled=1

gpgcheck=1

repo_gpgcheck=1

gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

EOF

wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

yum install -y docker-ce-18.06.1.ce-3.el7

systemctl enable docker && systemctl start docker

docker –version

docker version 18.06.1-ce, build e68fc7a

yum install -y kubelet kubeadm kubectl

systemctl enable kubelet

 


 

二、部署Master节点

1kubeadm 执行安装(注意前面yum安装的版本  在最后安装完成后有log打印  版本千万要对上  不然重来

kubeadm init --kubernetes-version=1.15.0 --apiserver-advertise-address=192.168.25.150 --image-repository registry.aliyuncs.com/google_containers --service-cidr=10.1.0.0/16 --pod-network-cidr=10.244.0.0/16

 

Ps:注意前一步yum安装的 kubelet kubeadm kubectl 的版本

集群初始化成功后返回如下信息:

kubeadm join 192.168.25.150:6443 --token v0h9d5.y6ryogyngkjv8463 --discovery-token-ca-cert-hash sha256:ec13b19b3b97fa8cf308e9a7e744a639f1ab4bc124b692931934ad6b9cf747f2

记录生成的最后部分内容,此内容需要在其它节点加入Kubernetes集群时执行。

 

2、配置kubectl

mkdir -p /root/.kube

cp /etc/kubernetes/admin.conf /root/.kube/config

kubectl get nodes

kubectl get cs

 

 

3.部署flannel网络

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml

 

 

#到这里 可以先让node加入集群

 

----------------------------

 

4、部署Dashboard

// 获取yaml文件

wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

 

// 向文件追加nodeport等

sed -i 's/k8s.gcr.io/loveone/g' kubernetes-dashboard.yaml

sed -i '/targetPort:/a\ \ \ \ \ \ nodePort: 30001\n\ \ type: NodePort' kubernetes-dashboard.yaml

// 创建pod和svc

kubectl create -f kubernetes-dashboard.yaml

 

// 检查状态

kubectl get deployment kubernetes-dashboard -n kube-system

kubectl get pods -n kube-system -o wide

kubectl get services -n kube-system

netstat -ntlp|grep 30001

在Firefox浏览器输入Dashboard访问地址:https://192.168.25.150:30001(Chrome玩不了)

// 查看访问Dashboard的认证令牌

kubectl create serviceaccount  dashboard-admin -n kube-system
kubectl create clusterrolebinding  dashboard-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
kubectl describe secrets -n kube-system $(kubectl -n kube-system get secret | awk '/dashboard-admin/{print $1}')

#下面是登陆dashboard的令牌

eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tZ3NxaHEiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiMmM0OGJiYWEtYWI4YS00MzA0LWFhYTktZDk2YzY2ODVhMDlkIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.b6fu2KxfJi7vTR7rUL5qOY_M3HJuCMaaAdcFioLqF9AoBg8bdy1OgGcv2PCNa-06KVip1pOz8-EsiNE81wI2pELfLu47eCTtqfLQSi_MF1LYm5jD5JLO0Cym5Vohf_cTi0DCOJZnO4TbWAxAxYb5xw6_TySbnOOvyrB6CVR_IWUZukLquHoF1s7Xg3km5NU8XOP973IOYpGnYGkXHT9aMHEUOfWxKfQ8LRgIvlvs2fwxeY7UNxajUVKlIEYNLP-zxU1FB7ZHySMUj-t6wMXU-91LY7BOEASnu8ad2PUs5a5BZA7CtriMXmJGGkStvlaW5Isc7kIKyoEgQTXLH4enTQ

 

三、部署Node节点

#只需加入集群即可

kubeadm join 192.168.25.150:6443 --token v0h9d5.y6ryogyngkjv8463 --discovery-token-ca-cert-hash sha256:ec13b19b3b97fa8cf308e9a7e744a639f1ab4bc124b692931934ad6b9cf747f2

 

安装完成:

master节点   kubectl get nodes查看即可

 


  PS:

  • CPU最少2H 内存最少2G  不然kubeadm会报错
  • 如果部署失败,可以执行kubeadm reset清理环境
  • 确定集群至少有一台cluster,并且可以正常通信,不然kubeadm会报错

整理自:https://www.kubernetes.org.cn/5462.html

 

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐