kubernates 1.20.6安装
kubernates 安装
1. 前置要求
- 硬件条件 三台主机 1主2从
- 硬件配置 master 2核4G slave 2核2G
2. 安装
-
访问GitHub 仓库 https://github.com/lework/kainstall
-
运行以下脚本
bash -c "$(curl -sSL https://cdn.jsdelivr.net/gh/lework/kainstall@master/kainstall-centos.sh)" \ - init \ --master 192.168.147.128 \ --worker 192.168.147.132,192.168.147.133 \ --user root \ --password 123123 \ --port 22 \ --version 1.20.6
经过漫长的等待 ,会有提示信息,然后输入k8s的管理命令确认kubectl cluster-info是否运行正常,如果不成功,查看下面的日志文件进行排坑
... xzO3coGy8vsFtAkZHLsTiFAWzjYZXKIZZx-cxaZvpYfzO-uNPa3UcFL2aKiqNS0Hr-kjHhFhcMxxH-yWuwodZYn4qzeI1ZIV_-Cg1wte1s3Covb15g [ops] etcd backup directory: /var/lib/etcd/backups See detailed log >>> /tmp/kainstall.t2964vNRW6/kainstall.log
3. 安装dashboard
-
-
下载
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.3.1/aio/deploy/recommended.yaml
-
查看dashboard是否运行kubectl get pod --namespace=kube-system,如下日志信息
NAME READY STATUS RESTARTS AGE coredns-8496bbfb78-7l9gs 1/1 Running 1 118m coredns-8496bbfb78-r87cr 1/1 Running 1 118m default-http-backend-6946487d9b-rshx5 1/1 Running 1 119m etcd-k8s-master-node1 1/1 Running 1 122m etcd-snapshot-1625813807-5s5xf 0/1 Completed 0 118m kube-apiserver-k8s-master-node1 1/1 Running 1 122m kube-controller-manager-k8s-master-node1 1/1 Running 1 122m kube-flannel-ds-9pg5p 1/1 Running 1 121m kube-flannel-ds-whbxz 1/1 Running 1 121m kube-flannel-ds-xxggv 1/1 Running 1 121m kube-proxy-cpnnx 1/1 Running 1 121m kube-proxy-fv62v 1/1 Running 1 121m kube-proxy-t29xk 1/1 Running 1 121m kube-scheduler-k8s-master-node1 1/1 Running 1 122m metrics-server-998c79b89-qzsmj 0/1 Running 1 120m
-
启动代理kubectl proxy
-
在本地进行ssh正向代理,记得配置免密
ssh -L localhost:8001:localhost:8001 -NT root@192.168.147.128
-
访问网页出现如下内容,说明服务启动完成
4. 创建dashboard用户
-
创建用户
kubectl create serviceaccount dashboard-admin -n kube-system
-
授权 (绑定用户为集群管理用户)
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin
-
查看token
kubectl describe -n=kube-system secret dashboard-admin-token-qqrjx
- 详细信息,复制token
Name: dashboard-admin-token-qqrjx Namespace: kube-system Labels: <none> Annotations: kubernetes.io/service-account.name: dashboard-admin kubernetes.io/service-account.uid: e3b577a7-fd60-4705-bfe9-df87d88b97f5 Type: kubernetes.io/service-account-token Data ==== ca.crt: 1066 bytes namespace: 11 bytes token: eyJhbGciOiJSUzI1NiIsImtpZCI6InhiLTVQTjBLVHRkd24zNkd5QWVXWXNZaUI0M0FyVkZBNWI4S0pXRWZta2MifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tcXFyangiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZTNiNTc3YTctZmQ2MC00NzA1LWJmZTktZGY4N2Q4OGI5N2Y1Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.IrVjifmz2Ka0utLv17jKxdtGXG2A6XvmqIO9tcLwTSmYcsnnsUYdKDV-nKzQt7RZZmsbdangCxHOSFNN-bFVyzltHgmnCji4ViJgsgG1ATw7GAAoZBcydm-1sf9XUoQvvXJ7pX-sthpXbPjAItzfoNw5I6Re4DniuhAqsMxjqiOCkreFhV-vc0uww88InPlrfuvYesonj_L0hJnrZJOZbJ7r1QPrery3x9PfGP7F19OMTUfe_iPIu_GFhED8u6aN8OR_uhDSE_EII1zQuLWYV6ksuaxG5s-RNfmJqLfG-HnEwJheJZ_63ceA-j4N4imZ_nNozUAC732ec4_MGIYgLA
5. 总结
- k8s的部署难度真不是一般的高,踩坑挺多的
- 感谢有一键部署工具,少了很多弯路,前期调研部署工具花了较多时间,官方提供的ansible playbook 安装 会遇到网络问题。
- master节点一定要4g内存,之前用2g内存会挂掉