# 配置域名
hostnamectl set-hostname master
# 配置dns
cat <<EOF >>/etc/hosts
10.211.55.11 master
10.211.55.12 node1
EOF
#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#关闭seliunux
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
#关闭交换空间
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
#配置内核参数,将桥接的IPv4流量传递到iptables的链
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源
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
# 添加Kubernetes源
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
# 添加docker源
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
# 安装docker
yum install -y docker-ce-18.06.1.ce-3.el7
# 启动docker
systemctl enable docker && systemctl start docker
# 配置Kubernetes driver 未systemd
cat <<EOF >/etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
# 重启docker
systemctl restart docker
# Docker version 18.06.1-ce, build e68fc7a
docker –version
# 安装Kubernetes 组件
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
# 在master进行Kubernetes集群初始化
kubeadm init --kubernetes-version=v1.15.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.211.55.11 --image-repository registry.aliyuncs.com/google_containers
# 输出kubeadm join 10.211.55.11:6443 --token d2fegj.0oali68pubm3ofdt --discovery-token-ca-cert-hash sha256:965c1fa5a6b4b87a24082e555ef73e79eb4dc1da9d34e16f144208ffbd2e6177 其他节点运行此命令
# 配置kubectl工具
mkdir -p /root/.kube
cp /etc/kubernetes/admin.conf /root/.kube/config
kubectl get nodes
kubectl get cs
# 配置flannel网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
# 安装dashboard
kubectl apply -f http://mirror.faasx.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
# 查看pods
kubectl get pods --all-namespaces
# 绑定角色
vi admin-user-role-binding.yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
kubectl create -f admin-user-role-binding.yaml
# 生成token
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
# 配置端口转发
ssh -L 8001:localhost:8001 root@10.211.55.11
# 登录地址
http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/#!/login
参考文章:
https://www.kubernetes.org.cn/5462.html
https://blog.frognew.com/2017/07/kubeadm-install-kubernetes-1.7.html
https://www.cnblogs.com/RainingNight/p/deploying-k8s-dashboard-ui.html