1、环境
docker2:172.25.27.102 | manager,node |
docker3:172.25.27.103 | node |
docker4:172.25.27.104 | node |
2、安装
docker2,docker3,docker4
(1)关闭swap
swapoff -a
selinux设置为disabled
vim /etc/fstab
关闭火墙/让火墙允许服务通过
安装
(2)、下载软件包,注意版本
yum源位置:阿里yum源
cri-tools-1.13.0-0.x86_64.rpm kubelet-1.15.0-0.x86_64.rpm
kubeadm-1.15.0-0.x86_64.rpm kubernetes-cni-0.7.5-0.x86_64.rpm
kubectl-1.15.0-0.x86_64.rpm
Yum install -y *
(3)、导入镜像
coredns.tar etcd.tar
kube-apiserver.tar kube-controller-manager.tar
kube-proxy.tar kube-scheduler.tar
pause.tar
For i in *.tar; do docker load -i $i ; done
(4)、使iptables生效
vim /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
sysctl --system 重读文件,使生效
3、集群搭建
主节点docker2初始化kubeadm
kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.25.17.102
报错:timeout
解决方法:
kubeadm reset 重置,重新执行初始化
其它节点加入集群,docker3,docker4加入集群
kubeadm join 172.25.17.102:6443 --token zbrnwl.cshxdc8k8kuucvhi --discovery-token-ca-cert-hash sha256:fed31a5092861e88e0035d9b943b5f34fb21b1c3b207f5c26e1709aa213cd2b7
主节点建立用户并授权管理集群
useradd kube
vim /etc/sudoers
kube ALL=(ALL) NOPASSWD:ALL
su - kube
授权kube用户管理集群
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
NAME STATUS ROLES AGE VERSION
docker2 Ready master 147m v1.15.0
docker3 Ready <none> 147m v1.15.0
docker4 Ready <none> 146m v1.15.0
kubectl get pods --all-namespaces 查看节点命名空间
kubectl get pods -n kube-system -owide 查看详细的信息
problem:The connection to the server localhost:8080 was refused - did you specify the right host or port?
解决方法:执行创建用户和授权
注:net.ipv4.ip_forward = 1
sysctl -a| grep ip_forward
vim /etc/sysctl.conf
sysctl -p
4、UI部署
1)、部署
docker2,docker3,docker4导入镜像
kubernetes-dashboard.tar flannel.tar
补全命令
echo "source <(kubectl completion bash)" >> .bashrc
docker2的yaml文件部署服务
kubectl create -f kubernetes-dashboard.yaml
kubectl create -f kube-flannel.yml
kubectl edit service kubernetes-dashboard -n kube-system 修改 kubernetes-dashboard服务:type : NodePort,方便访问
kubectl describe svc kubernetes-dashboard -n kube-system 查看kubernetes-dashboard服务信息
Name: kubernetes-dashboard
Namespace: kube-system
Labels: k8s-app=kubernetes-dashboard
Annotations: <none>
Selector: k8s-app=kubernetes-dashboard
Type: NodePort
IP: 10.108.214.77
Port: <unset> 443/TCP
TargetPort: 8443/TCP
NodePort: <unset> 32675/TCP
Endpoints: 10.244.0.3:8443
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
访问:https://172.25.27.102:32675 查看界面
2)、登陆
vim /home/kube/dashboard-admin.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
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 kubernetes-admin.yaml
kubectl get secrets -n kube-system | grep admin
admin-user-token-zrs8s kubernetes.io/service-account-token 3 106m
kubectl describe secrets admin-user-token-zrs8s -n kube-system 获取token
Name: admin-user-token-zrs8s
Namespace: kube-system
Labels: <none>
Annotations: kubernetes.io/service-account.name: admin-user
kubernetes.io/service-account.uid: 37c52860-8fcd-45a5-b2d7-ffc94875af04
Type: kubernetes.io/service-account-token
Data
====
ca.crt: 1025 bytes
namespace: 11 bytes
token: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLXpyczhzIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIzN2M1Mjg2MC04ZmNkLTQ1YTUtYjJkNy1mZmM5NDg3NWFmMDQiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.K90mfJkMGFIEyv6-T86ENgaLzueFnBuCJ-kDEDvVbOo4yiKtgfYgdyzsdcGdxQj1IfLs-aiRVuogX7tWu69bu2Am1-9xfH4wx_TsivT-xGB4j3KMeyYbeCrtGjyf1PKq3JXzuFR51X77aQdn9M9GqnM4j96j5TyzGIdSpInRid3ov1FbrLYfEELv93DpJdOiCWZ7CL5woSaL31Fl0X-KczKRjrRLQ7Ib7iyV3ZWDV5Mf1sn0wXSRhOwpiGN11RolXKqB9VfEcJcgmJNLqrWW7K6zoKLrYON7zuloEsAEbrYSxa6gQPl7W9k3OW1SFb3NI2FGGcf3tG6KnMkMuKwH9A