软件版本:
kubelet:V1.13.3
docker: 18.06.1
实验环境:
Centos 7.5.1804
说明:
初学。安装步骤参考了阿良的文档,并做了部分修改。
步骤如下:
1、关闭防火墙:
$ systemctl stop firewalld
$ systemctl disable firewalld
2、关闭selinux:
$ sed -i ‘s/enforcing/disabled/‘ /etc/selinux/config
$ setenforce 0
3、关闭swap:
$ swapoff -a $ 临时
$ vim /etc/fstab $ 永久
sed -ri ‘s/.*swap.*/#&/‘ /etc/fstab
4、添加主机名与IP对应关系(记得设置主机名):
$ cat /etc/hosts
192.168.0.11 k8s-master
192.168.0.12 k8s-node1
192.168.0.13 k8s-node2
5、将桥接的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
6、安装docker
$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce-18.06.1.ce-3.el7
$ systemctl enable docker && systemctl start docker
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
7、添加阿里云源
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
8、安装kubeadm,kubelet,kubectl(所有节点安装docker,kubeadm,kubelet)
yum install -y kubelet-1.13.3 kubeadm-1.13.3 kubectl-1.13.3 kubernetes-cni-0.6.0
systemctl enable kubelet
9、部署k8s master
kubeadm init \
--apiserver-advertise-address=192.168.0.11 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.13.3 \
--service-cidr=10.1.0.0/16\
--pod-network-cidr=10.244.0.0/16
10、使用kubectl工具
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl get nodes
11、安装pod网络插件(CNI)
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
sed -i ‘s/quay.io\/coreos/registry.cn-beijing.aliyuncs.com\/imcto/g‘ kube-flannel.yml
kubectl apply -f kube-flannel.yml
12、加入kubernetes node
向集群添加新节点,执行在kubeadm init输出的kubeadm join命令:
$ kubeadm join 192.168.31.64:6443 --token l79g5t.6ov4jkddwqki1dxe --discovery-token-
ca-cert-hash sha256:4f07f9068c543130461c9db368d62b4aabc22105451057f887defa35f47fa076
13、部署dashboard
修改镜像地址为 reg.qiniu.com/k8s/kubernetes-dashboard-amd64:v1.8.3
默认Dashboard只能集群内部访问,修改Service为NodePort类型,暴露到外部:
kind: Service
apiVersion: v1
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:
type: NodePort
ports:
- port: 443
targetPort: 8443
nodePort: 30001
selector:
k8s-app: kubernetes-dashboard
$ kubectl apply -f kubernetes-dashboard.yaml
访问地址:https://NodeIP:30001
14、创建service account并绑定默认cluster-admin管理员集群角色:
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}‘)
15、使用输出的token登录Dashboard。
16、使用kubeconfig登录Dashboard
# 获取dashboard-admin的name
kubectl describe secret -n kube-system dashboard-admin
# 把dashboard的token放入变量,方便后面调用(这里的token是base64编码,此处需要进行解码操作)
DASH_TOCKEN=$(kubectl get secret -n kube-system dashboard-admin-token-sj7kl -o jsonpath={.data.token}|base64 -d)
# 配置上下文和当前上下文
kubectl config set-cluster kubernetes --server=192.168.0.11:6443 --kubeconfig=/root/dashbord-admin.conf
kubectl config set-credentials dashboard-admin --token=$DASH_TOCKEN --kubeconfig=/root/dashbord-admin.conf
kubectl config set-context [email protected] --cluster=kubernetes --user=dashboard-admin --kubeconfig=/root/dashbord-admin.conf
kubectl config use-context [email protected] --kubeconfig=/root/dashbord-admin.conf
17、使用dashbord-admin.conf登录kube_dashboard
原文地址:https://www.cnblogs.com/Vivi-87/p/11169177.html