kubesphere3.0的安装完整文档
kubesphere3.0的安裝文檔
https://www.yuque.com/leifengyang/kubesphere/hxzk3t#SAP5W
基于kubernetes環(huán)境安裝kubesphere3.0的安裝文檔
本文檔主要是在centos7系統(tǒng)下基于kubernetes環(huán)境安裝kubesphere3.0的安裝文檔。
1 環(huán)境準備
1.1 系統(tǒng)要求
本地虛擬機三臺
要求:centos7.6~7.8;以下為
https://kuboard.cn/install/install-k8s.html#%E6%A3%80%E6%9F%A5-centos-hostname 網(wǎng)站的檢驗結果。
| 7.8 | 是 | 已經驗證 |
| 7.7 | 是 | 已經驗證 |
| 7.6 | 是 | 已經驗證 |
| 7.5 | 否 | 已證實會出現(xiàn) kubelet 無法啟動的問題 |
| 7.4 | 否 | 已證實會出現(xiàn) kubelet 無法啟動的問題 |
| 7.3 | 否 | 已證實會出現(xiàn) kubelet 無法啟動的問題 |
| 7.2 | 否 | 已證實會出現(xiàn) kubelet 無法啟動的問題 |
1.2 虛擬機安裝步驟
安裝虛擬機比較的簡單,這里不做介紹。
1.2.1 創(chuàng)建客戶機的向導
1.2.1.1 創(chuàng)建新的虛擬機
點擊創(chuàng)建新的虛擬機。
1.2.1.2 新建虛擬機向導
選擇典型,點擊下一步。
1.2.1.3 安裝客戶機的操作系統(tǒng)
選擇稍后安裝操作系統(tǒng),點擊下一步。
1.2.1.4 選擇客戶機的操作系統(tǒng)類型
我們這里安裝的Linux Centos7版本。這里我們選擇的Linux系統(tǒng)。版本選擇Redhat Enterpise Linux7 64位。
1.2.1.5 命名客戶機和存儲位置
這里根據(jù)自己的情況設置客戶機的名稱以及客戶存儲的本地的位置。
1.2.1.6 配置客戶機的磁盤的大小
默認給出的20G,這里我設置的大一寫。設置成100G。點擊下一步。
1.2.1.7 已經準備創(chuàng)建好的客戶機
點擊完成。基本的客戶機的創(chuàng)建向導完成。
1.2.1.8 配置客戶機的屬性
1.2.1.8.1 內存配置大小
這里我們一般設置成企業(yè):8G、個人使用2G做演示。
1.2.1.8.2 處理器配置
處理器配置,我們一般配置成2個處理器。
1.2.1.8.3 硬盤配置
這里默認選擇。不需要操作。
1.2.1.8.4 CD/DVD配置
設備狀態(tài)設置成啟動時連接,選擇ISO鏡像文件連接并配置好連接。
1.2.1.8.5 網(wǎng)絡適配器配置
在本地配置下我們使用的NAT模式。如果在企業(yè)搭建上,建議使用橋接模式。
1.2.1.8.6 USB控制器配置
對服務器來說,不需要該設備。移除即可。
1.2.1.8.7 聲卡配置
對服務器來說,不需要該設備。移除即可。
1.2.1.8.8 打印機配置
對服務器來說,不需要該設備。移除即可。
1.2.1.8.9 顯示器配置
不需要操作,使用默認即可。
這里客戶機的基本的配置基本完成。
1.2.1.9 安裝客戶機的步驟
1.2.1.9.1 開始安裝客戶機系統(tǒng)
1.2.1.9.2 按下回車開始安裝配置虛擬機安裝屬性
等待加載系統(tǒng)鏡像完畢。
1.2.1.9.3 選擇客戶機的系統(tǒng)語言
這里我們選擇中文簡體。點擊繼續(xù)。
1.2.1.9.4 設置安裝客戶機的基本配置
1.2.1.9.4.1 安裝選擇類型
點擊完成。
1.2.1.9.5 開始安裝客戶機系統(tǒng)
點擊開始安裝。
1.2.1.9.6 用戶設置
創(chuàng)建密碼。自己記住即可。這里是管理員登錄密碼。
1.2.1.9.7 安裝系統(tǒng)進行中
此處需要等待一段時間,不同的機器配置等待的時間不一致。
1.2.1.9.8 初始化客戶機的步驟
安裝成功之后,我們看到以下的圖。
點擊重啟即可。
1.2.1.9.9 接受許可證
勾選我同意許可協(xié)議。重啟系統(tǒng)。輸入用戶名密碼登錄到系統(tǒng)。至此我們的系統(tǒng)客戶機安裝成功。
1.2.1.9.10 系統(tǒng)歡迎頁面
選擇漢語,點擊前進。
1.2.1.9.11 自定義鍵盤輸入法
選擇漢語,點擊前進。
1.2.1.9.12 隱私設置
點擊前進。
1.2.1.9.13 在線登錄賬號
這里我們跳過即可。
1.2.1.9.14 開始使用系統(tǒng)
1.2.1.9.15 打開終端輸入命令行查詢IP地址
我們連接的ens33的網(wǎng)卡,因此我們得到的本地的IP地址為:192.168.196.128,這里每個人的IP地址不一樣。根據(jù)自己的實際情況獲取IP地址。
1.2.1.9.15.1 注意,如果沒有ip顯示:
你可以在/etc/sysconfig/network-scripts 這個目錄下面的ifcfg-ens33這個文件里面的O****NBOOT=no,修改成ONBOOT=yes,然后通過命于重新啟動網(wǎng)絡服務。
重新啟動網(wǎng)絡服務:
/etc/init.d/network restart 或 service network restart
然后可設置靜態(tài)網(wǎng)絡ip:
設置靜態(tài)ip的話,一定要記住,設置GATEWAY網(wǎng)關的時候要跟虛擬網(wǎng)絡編輯器的網(wǎng)關要一致,否則無法上網(wǎng)!!!
設置完靜態(tài)IP以后重新啟動網(wǎng)絡服務:
/etc/init.d/network restart 或 service network restart
然后測試能不能上網(wǎng):
ping www.baidu.com
1.2.1.9.16 使用外部客戶端工具連接
這里虛擬機安裝centos7系統(tǒng)完成。
安裝安裝上述的安裝方式,需要安裝三臺虛擬機。
1.3 虛擬機環(huán)境如下
| 192.168.142.144 | master節(jié)點 | 8G內存 4核CPU |
| 192.168.142.145 | node1節(jié)點 | 8G內存 4核CPU |
| 192.168.142.146 | node2節(jié)點 | 8G內存 4核CPU |
1.4 前置步驟說明
centos 版本為 7.6 或 7.7、CPU 內核數(shù)量大于等于 2,且內存大于等于 4G。
hostname 不是 localhost,且不包含下劃線、小數(shù)點、大寫字母。
任意節(jié)點都有固定的內網(wǎng) IP 地址(集群機器統(tǒng)一內網(wǎng))。
任意節(jié)點上 IP 地址 可互通(無需 NAT 映射即可相互訪問),且沒有防火墻、安全組隔離。
任意節(jié)點不會直接使用 docker run 或 docker-compose 運行容器,Pod。
1.4.1 安裝基礎工具
yum install -y wget && yum install -y vim && yum install -y lsof && yum install -y net-tools
1.4.2 配置hosts的地址名稱
vim /etc/hosts 192.168.142.147 k8s-node1192.168.142.148 k8s-node2192.168.142.149 k8s-node3hostnamectl set-hostname :指定新的hostname su 切換過來
1.4.3 關閉防火墻或者阿里云開通安全組端口訪問
systemctl stop firewalldsystemctl disable firewalld 執(zhí)行關閉命令: systemctl stop firewalld.service再次執(zhí)行查看防火墻命令:systemctl status firewalld.service執(zhí)行開機禁用防火墻自啟命令 : systemctl disable firewalld.service
1.4.4 關閉 selinux
sed -i ‘s/enforcing/disabled/’ /etc/selinux/configsetenforce 0cat /etc/selinux/config
1.4.5 關閉 swap
swapoff -a #臨時sed -ri ‘s/.swap./#&/’ /etc/fstab #永久free -l -h
1.4.6 將橋接的 IPv4 流量傳遞到 iptables 的鏈
1.4.6.1 如果沒有/etc/sysctl.conf文件的話直接執(zhí)行
echo “net.ipv4.ip_forward = 1” >> /etc/sysctl.confecho “net.bridge.bridge-nf-call-ip6tables = 1” >> /etc/sysctl.confecho “net.bridge.bridge-nf-call-iptables = 1” >> /etc/sysctl.confecho “net.ipv6.conf.all.disable_ipv6 = 1” >> /etc/sysctl.confecho “net.ipv6.conf.default.disable_ipv6 = 1” >> /etc/sysctl.confecho “net.ipv6.conf.lo.disable_ipv6 = 1” >> /etc/sysctl.confecho “net.ipv6.conf.all.forwarding = 1” >> /etc/sysctl.conf
1.4.6.2 如果有該文件可以執(zhí)行以下命令
sed -i “s#^net.ipv4.ip_forward.#net.ipv4.ip_forward=1#g" /etc/sysctl.confsed -i "s#^net.bridge.bridge-nf-call-ip6tables.#net.bridge.bridge-nf-call-ip6tables=1#g” /etc/sysctl.confsed -i “s#^net.bridge.bridge-nf-call-iptables.#net.bridge.bridge-nf-call-iptables=1#g" /etc/sysctl.confsed -i "s#^net.ipv6.conf.all.disable_ipv6.#net.ipv6.conf.all.disable_ipv6=1#g” /etc/sysctl.confsed -i “s#^net.ipv6.conf.default.disable_ipv6.#net.ipv6.conf.default.disable_ipv6=1#g" /etc/sysctl.confsed -i "s#^net.ipv6.conf.lo.disable_ipv6.#net.ipv6.conf.lo.disable_ipv6=1#g” /etc/sysctl.confsed -i “s#^net.ipv6.conf.all.forwarding.*#net.ipv6.conf.all.forwarding=1#g” /etc/sysctl.conf
1.4.6.3 執(zhí)行命令以應用
sysctl -p
1.4.7 安裝Docker環(huán)境(所有節(jié)點)
1.4.7.1 卸載舊版本的docker
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-engine
1.4.7.2 安裝基礎依賴
yum install -y yum-utils \device-mapper-persistent-data \lvm2
1.4.7.3 配置docker yum源
sudo yum-config-manager --add-repo \http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
1.4.7.4 安裝并啟動 docker
yum install -y docker-ce-19.03.8 docker-ce-cli-19.03.8 containerd.iosystemctl enable dockersystemctl start dockerdocker version
1.4.7.5 配置docker加速
1.4.7.5.1 創(chuàng)建docker加速文件夾
sudo mkdir -p /etc/docker
1.4.7.5.2 登錄阿里云獲取鏡像
如果沒有的話,需要手動輸入“容器鏡像服務”。
sudo tee /etc/docker/daemon.json <<-‘EOF’{ “registry-mirrors”: [“https://11l3ppzn.mirror.aliyuncs.com”]}EOF
systemctl daemon-reloadsystemctl restart docker
1.4.8 安裝k8s環(huán)境
1.4.8.1 安裝k8s、kubelet、kubeadm、kubectl(所有節(jié)點)
1.4.8.1.1 配置K8S的yum源
cat < /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=0repo_gpgcheck=0gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgEOF
1.4.8.1.2 卸載舊版本
1.4.8.1.3 安裝kubelet、kubeadm、kubectl
yum install -y kubelet-1.17.3 kubeadm-1.17.3 kubectl-1.17.3
必須等待三臺主機安裝成功。
1.4.8.1.4 開機啟動和重啟kubelet
systemctl enable kubelet && systemctl start kubelet
注意,如果此時查看kubelet的狀態(tài),他會無限重啟,等待接收集群命令,和初始化。這個是正常的。
1.4.8.2 初始化所有節(jié)點
1.4.8.2.1 創(chuàng)建一個shell腳本內容如下
新建一個shell腳本名稱為image.sh
vi images.sh #!/bin/bashimages=( kube-apiserver:v1.17.3 kube-proxy:v1.17.3 kube-controller-manager:v1.17.3 kube-scheduler:v1.17.3 coredns:1.6.5 etcd:3.4.3-0 pause:3.1)for imageName in images[@];dodockerpullregistry.cn?hangzhou.aliyuncs.com/googlecontainers/{images[@]} ; do docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/images[@];dodockerpullregistry.cn?hangzhou.aliyuncs.com/googlec?ontainers/imageNamedone
1.4.8.2.2 將該腳本授予可執(zhí)行的權限
chmod -R 700 images.sh
1.4.8.2.3 執(zhí)行該腳本命令
./images.sh 比較慢,耐心等待
1.4.8.2.4 初始化master節(jié)點
注意,該操作只是在master節(jié)點之后構建環(huán)境。
kubeadm init --apiserver-advertise-address=192.168.142.144 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.17.3 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.244.0.0/16
–apiserver-advertise-address=10.12.0.9
這里的地址需要修改成master對應的IP地址。
1.4.8.2.4.1 如果輸入以上內容報錯:
[ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
[preflight] If you know what you are doing, you can make a check non-fatal with --ignore-preflight-errors=...
To see the stack trace of this error execute with --v=5 or higher
解決方案:
echo “1” >/proc/sys/net/bridge/bridge-nf-call-iptables
初始化完成。
1.4.8.2.5 配置 kubectl
這里注意的是,一定成初始化成功后面獲取復制。
mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown (id?u):(id -u):(id?u):(id -g) $HOME/.kube/config
1.4.8.2.6 部署網(wǎng)絡插件
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
1.4.8.2.7 查看節(jié)點運行的情況
kubectl get nodes
1.4.8.2.8 查看所有的pod的運行的情況
kubectl get pods -A
這里需要注意的是,必須等所有的狀態(tài)為Runing才能進行下一步操作。
1.4.8.2.8.1 如果上面操作導致pod有報錯:
比如爆
error: the server doesn’t have a resource type “calico-kube-controllers-544658cf79-bv5mj”
這個異常
解決: 可以試下重啟一下kubelet服務,然后等待一下,應該就可以了
systemctl restart kubelet
1.4.8.2.9 執(zhí)行令牌(在從節(jié)點操作)
這里注意的是,一定成初始化成功后面獲取復制。
| #1、如果超過2小時忘記了令牌,可以這樣做``kubeadm token create --print-join-command #打印新令牌kubeadm token create --ttl 0 --print-join-command #創(chuàng)建個永不過期的令牌 |
加入令牌完成。
1.4.8.2.10 在主節(jié)點查看節(jié)點運行的情況
kubectl get nodes
1.4.8.2.11 查看所有的pod的運行的情況
kubectl get pods -A
這里需要注意的是,必須等所有的狀態(tài)為Runing才能進行下一步操作。
1.4.9 搭建NFS作為默認sc(所有節(jié)點)
1.4.9.1 配置NFS服務器
yum install -y nfs-utils echo “/nfs/data/ *(insecure,rw,sync,no_root_squash)” > /etc/exports
1.4.9.2 創(chuàng)建nfs服務器目錄(主節(jié)點作為服務器,主節(jié)點操作)
mkdir -p /nfs/data
1.4.9.3 啟動nfs服務命令
systemctl enable rpcbindsystemctl enable nfs-serversystemctl start rpcbindsystemctl start nfs-serverexportfs -r
1.4.9.4 檢查配置是否生效
exportfs
1.4.9.5 測試Pod直接掛載NFS了(主節(jié)點操作)
1.4.9.5.1 在opt目錄下創(chuàng)建一個nginx.yaml的文件
vim nginx.yaml
1.4.9.5.2 寫入以下的命令
apiVersion: v1kind: Podmetadata: name: vol-nfs namespace: defaultspec: volumes: - name: html nfs: path: /nfs/data #1000G server: 192.168.142.144 #自己的nfs服務器地址 containers: - name: myapp image: nginx volumeMounts: - name: html mountPath: /usr/share/nginx/html/
這里注意:server: 10.12.0.9 #自己的nfs服務器地址
1.4.9.5.3 應用該yaml的pod服務
kubectl apply -f nginx.yaml
1.4.9.5.4 檢查該pod是否允許狀態(tài)
kubectl get pod
kubectl get pods -A
這里需要注意的是,必須等所有的狀態(tài)為Runing才能進行下一步操作。
1.4.9.5.5 查看nginx的pod的IP訪問地址
kubectl get pod -o wide
訪問地址: 10.244.107.193
1.4.9.5.6 本地測試訪問pod信息
curl 10.244.107.193
這里我們看到的是訪問的頁面是403,我們可以訪問具體頁面
我們需要在/nfs/data/下新建一個index.html文件。
cd /nfs/data/vim index.html
1.4.9.5.7 再次測試訪問pod信息
curl 10.244.107.193
1.4.10 搭建NFS-Client
服務器端防火墻開放111、662、875、892、2049的 tcp / udp 允許,否則遠端客戶無法連接。
1.4.10.1 安裝客戶端工具(node節(jié)點操作)
showmount -e 192.168.142.144
該IP地址是master的IP地址。
1.4.10.2 創(chuàng)建同步文件夾
mkdir /root/nfsmountls /root
1.4.10.3 將客戶端的/root/nfsmount和/nfs/data/做同步(node節(jié)點操作)
mount -t nfs 192.168.142.144:/nfs/data/ /root/nfsmount
10.12.0.9:是nfs的服務器的地址,這里是master的IP地址。
1.4.10.4 查看原來的文件信息(從)機器
cat index.html
1.4.10.5 修改原來的文件信息(主)機器
cat index.html
1.4.10.6 在另外的機器上查看效果
cat index.html
1.4.11 設置動態(tài)供應
1.4.11.1 創(chuàng)建provisioner(NFS環(huán)境前面已經搭好)
| 名稱 | nfs-storage | 自定義存儲類名稱 |
| NFS Server | 192.168.142.147 | NFS服務的IP地址 |
| NFS Path | /nfs/data | NFS服務所共享的路徑 |
1.4.11.1.1 先創(chuàng)建授權(master節(jié)點操作)
vim nfs-rbac.yaml 在opt目錄下
新建內容如下:
—apiVersion: v1kind: ServiceAccountmetadata: name: nfs-provisioner—kind: ClusterRoleapiVersion: rbac.authorization.k8s.io/v1metadata: name: nfs-provisioner-runnerrules: - apiGroups: [""] resources: [“persistentvolumes”] verbs: [“get”, “l(fā)ist”, “watch”, “create”, “delete”] - apiGroups: [""] resources: [“persistentvolumeclaims”] verbs: [“get”, “l(fā)ist”, “watch”, “update”] - apiGroups: [“storage.k8s.io”] resources: [“storageclasses”] verbs: [“get”, “l(fā)ist”, “watch”] - apiGroups: [""] resources: [“events”] verbs: [“watch”, “create”, “update”, “patch”] - apiGroups: [""] resources: [“services”, “endpoints”] verbs: [“get”,“create”,“l(fā)ist”, “watch”,“update”] - apiGroups: [“extensions”] resources: [“podsecuritypolicies”] resourceNames: [“nfs-provisioner”] verbs: [“use”]—kind: ClusterRoleBindingapiVersion: rbac.authorization.k8s.io/v1metadata: name: run-nfs-provisionersubjects: - kind: ServiceAccount name: nfs-provisioner namespace: defaultroleRef: kind: ClusterRole name: nfs-provisioner-runner apiGroup: rbac.authorization.k8s.io—kind: DeploymentapiVersion: apps/v1metadata: name: nfs-client-provisionerspec: replicas: 1 strategy: type: Recreate selector: matchLabels: app: nfs-client-provisioner template: metadata: labels: app: nfs-client-provisioner spec: serviceAccount: nfs-provisioner containers: - name: nfs-client-provisioner image: lizhenliang/nfs-client-provisioner volumeMounts: - name: nfs-client-root mountPath: /persistentvolumes env: - name: PROVISIONER_NAME value: storage.pri/nfs - name: NFS_SERVER value: 192.168.142.144 - name: NFS_PATH value: /nfs/data volumes: - name: nfs-client-root nfs: server: 192.168.142.144 path: /nfs/data
這個鏡像中volume的mountPath默認為/persistentvolumes,不能修改,否則運行時會報錯。紅色的必須是自己的master的IP地址。
1.4.11.1.2 執(zhí)行創(chuàng)建nfs的yaml文件信息
kubectl apply -f nfs-rbac.yaml
1.4.11.1.3 如果發(fā)現(xiàn)pod有問題,想刪除pod進行重新kubectl apply-f nfs-rbac.yaml的話,可以參照這個博客文檔:
https://blog.csdn.net/qq_43542988/article/details/101277263?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
1.4.11.1.4 查看pod的狀態(tài)信息
kubectl get pods -A 如果報錯:查看報錯信息,這個命令:kubectl describe pod xxx -n kube-system
1.4.11.1.5 創(chuàng)建storageclass(master節(jié)點操作)
vim storageclass-nfs.yaml apiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: storage-nfsprovisioner: storage.pri/nfsreclaimPolicy: Delete
1.4.11.1.6 應用storageclass-nfs.yaml文件
kubectl apply -f storageclass-nfs.yaml
1.4.11.1.7 修改默認的驅動
kubectl patch storageclass storage-nfs -p ‘{“metadata”: {“annotations”:{“storageclass.kubernetes.io/is-default-class”:“true”}}}’
kubectl get sc
1.4.12 安裝metrics-server
1.4.12.1 準備metrics-server.yaml文件(主節(jié)點操作)
vim metrics-server.yaml
1.4.12.2 編寫以下的內容
—apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: system:aggregated-metrics-reader labels: rbac.authorization.k8s.io/aggregate-to-view: “true” rbac.authorization.k8s.io/aggregate-to-edit: “true” rbac.authorization.k8s.io/aggregate-to-admin: "true"rules:- apiGroups: [“metrics.k8s.io”] resources: [“pods”, “nodes”] verbs: [“get”, “l(fā)ist”, “watch”]—apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: metrics-server:system:auth-delegatorroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:auth-delegatorsubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system—apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: metrics-server-auth-reader namespace: kube-systemroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: extension-apiserver-authentication-readersubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system—apiVersion: apiregistration.k8s.io/v1beta1kind: APIServicemetadata: name: v1beta1.metrics.k8s.iospec: service: name: metrics-server namespace: kube-system group: metrics.k8s.io version: v1beta1 insecureSkipTLSVerify: true groupPriorityMinimum: 100 versionPriority: 100—apiVersion: v1kind: ServiceAccountmetadata: name: metrics-server namespace: kube-system—apiVersion: apps/v1kind: Deploymentmetadata: name: metrics-server namespace: kube-system labels: k8s-app: metrics-serverspec: selector: matchLabels: k8s-app: metrics-server template: metadata: name: metrics-server labels: k8s-app: metrics-server spec: serviceAccountName: metrics-server volumes: # mount in tmp so we can safely use from-scratch images and/or read-only containers - name: tmp-dir emptyDir: {} containers: - name: metrics-server image: mirrorgooglecontainers/metrics-server-amd64:v0.3.6 imagePullPolicy: IfNotPresent args: - --cert-dir=/tmp - --secure-port=4443 - --kubelet-insecure-tls - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname ports: - name: main-port containerPort: 4443 protocol: TCP securityContext: readOnlyRootFilesystem: true runAsNonRoot: true runAsUser: 1000 volumeMounts: - name: tmp-dir mountPath: /tmp nodeSelector: kubernetes.io/os: linux kubernetes.io/arch: “amd64”—apiVersion: v1kind: Servicemetadata: name: metrics-server namespace: kube-system labels: kubernetes.io/name: “Metrics-server” kubernetes.io/cluster-service: "true"spec: selector: k8s-app: metrics-server ports: - port: 443 protocol: TCP targetPort: main-port—apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: system:metrics-serverrules:- apiGroups: - “” resources: - pods - nodes - nodes/stats - namespaces - configmaps verbs: - get - list - watch—apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: system:metrics-serverroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:metrics-serversubjects:- kind: ServiceAccount name: metrics-server namespace: kube-system
1.4.12.3 應用該文件pod
kubectl apply -f metrics-server.yaml
1.4.12.4 查看部署的應用信息狀態(tài)
kubectl get pod -A
1.4.12.5 查看系統(tǒng)的監(jiān)控狀態(tài)
kubectl top nodes 如果運行kubectl top nodes這個命令,爆metrics not available yet 這個命令還沒有用,那就稍等一會,就能用了
這里,kubesphere3.0的前置環(huán)境全部結束。
1.5 安裝kubesphere v3.0.0
1.5.1 文檔地址
https://kubesphere.com.cn/
1.5.2 部署文檔地址
https://kubesphere.com.cn/docs/quick-start/minimal-kubesphere-on-k8s/
1.5.3 安裝步驟說明(master節(jié)點)
1.5.3.1 安裝集群配置文件
1.5.3.1.1 準備配置文件cluster-configuration.yaml
vim cluster-configuration.yaml
1.5.3.1.2 編寫以下的內容配置
—apiVersion: installer.kubesphere.io/v1alpha1kind: ClusterConfigurationmetadata: name: ks-installer namespace: kubesphere-system labels: version: v3.0.0spec: persistence: storageClass: “” # If there is not a default StorageClass in your cluster, you need to specify an existing StorageClass here. authentication: jwtSecret: “” # Keep the jwtSecret consistent with the host cluster. Retrive the jwtSecret by executing “kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v “apiVersion” | grep jwtSecret” on the host cluster. etcd: monitoring: true # Whether to enable etcd monitoring dashboard installation. You have to create a secret for etcd before you enable it. endpointIps: 10.12.0.9 # etcd cluster EndpointIps, it can be a bunch of IPs here. port: 2379 # etcd port tlsEnable: true common: mysqlVolumeSize: 20Gi # MySQL PVC size. minioVolumeSize: 20Gi # Minio PVC size. etcdVolumeSize: 20Gi # etcd PVC size. openldapVolumeSize: 2Gi # openldap PVC size. redisVolumSize: 2Gi # Redis PVC size. es: # Storage backend for logging, events and auditing. # elasticsearchMasterReplicas: 1 # total number of master nodes, it’s not allowed to use even number # elasticsearchDataReplicas: 1 # total number of data nodes. elasticsearchMasterVolumeSize: 4Gi # Volume size of Elasticsearch master nodes. elasticsearchDataVolumeSize: 20Gi # Volume size of Elasticsearch data nodes. logMaxAge: 7 # Log retention time in built-in Elasticsearch, it is 7 days by default. elkPrefix: logstash # The string making up index names. The index name will be formatted as ks-<elk_prefix>-log. console: enableMultiLogin: true # enable/disable multiple sing on, it allows an account can be used by different users at the same time. port: 30880 alerting: # (CPU: 0.3 Core, Memory: 300 MiB) Whether to install KubeSphere alerting system. It enables Users to customize alerting policies to send messages to receivers in time with different time intervals and alerting levels to choose from. enabled: true auditing: # Whether to install KubeSphere audit log system. It provides a security-relevant chronological set of records,recording the sequence of activities happened in platform, initiated by different tenants. enabled: true devops: # (CPU: 0.47 Core, Memory: 8.6 G) Whether to install KubeSphere DevOps System. It provides out-of-box CI/CD system based on Jenkins, and automated workflow tools including Source-to-Image & Binary-to-Image. enabled: true jenkinsMemoryLim: 2Gi # Jenkins memory limit. jenkinsMemoryReq: 1500Mi # Jenkins memory request. jenkinsVolumeSize: 8Gi # Jenkins volume size. jenkinsJavaOpts_Xms: 512m # The following three fields are JVM parameters. jenkinsJavaOpts_Xmx: 512m jenkinsJavaOpts_MaxRAM: 2g events: # Whether to install KubeSphere events system. It provides a graphical web console for Kubernetes Events exporting, filtering and alerting in multi-tenant Kubernetes clusters. enabled: true ruler: enabled: true replicas: 2 logging: # (CPU: 57 m, Memory: 2.76 G) Whether to install KubeSphere logging system. Flexible logging functions are provided for log query, collection and management in a unified console. Additional log collectors can be added, such as Elasticsearch, Kafka and Fluentd. enabled: true logsidecarReplicas: 2 metrics_server: # (CPU: 56 m, Memory: 44.35 MiB) Whether to install metrics-server. IT enables HPA (Horizontal Pod Autoscaler). enabled: false monitoring: # prometheusReplicas: 1 # Prometheus replicas are responsible for monitoring different segments of data source and provide high availability as well. prometheusMemoryRequest: 400Mi # Prometheus request memory. prometheusVolumeSize: 20Gi # Prometheus PVC size. # alertmanagerReplicas: 1 # AlertManager Replicas. multicluster: clusterRole: none # host | member | none # You can install a solo cluster, or specify it as the role of host or member cluster. networkpolicy: # Network policies allow network isolation within the same cluster, which means firewalls can be set up between certain instances (Pods). # Make sure that the CNI network plugin used by the cluster supports NetworkPolicy. There are a number of CNI network plugins that support NetworkPolicy, including Calico, Cilium, Kube-router, Romana and Weave Net. enabled: true notification: # Email Notification support for the legacy alerting system, should be enabled/disabled together with the above alerting option. enabled: true openpitrix: # (2 Core, 3.6 G) Whether to install KubeSphere Application Store. It provides an application store for Helm-based applications, and offer application lifecycle management. enabled: true servicemesh: # (0.3 Core, 300 MiB) Whether to install KubeSphere Service Mesh (Istio-based). It provides fine-grained traffic management, observability and tracing, and offer visualization for traffic topology. enabled: true
endpointIps: 10.12.0.9:master節(jié)點的地址。
1.5.3.1.3 準備配置文件kubesphere-installer.yaml文件
1.5.3.1.4 分別執(zhí)行兩個文件
kubectl apply -f kubesphere-installer.yamlkubectl apply -f cluster-configuration.yaml
1.5.3.1.5 監(jiān)控安裝的日志信息
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath=’{.items[0].metadata.name}’) -f
1.5.3.1.6 查看pod啟動狀態(tài)信息
kubectl get pods -A
需要等待漫長的時間。喝杯茶,抽支煙。
1.5.4 訪問驗證是否安裝成功
訪問地址:
http://192.168.142.141:30880/login
帳號:admin
密碼:P@88w0rd
1.5.4.1.1.1 解決prometheus一直沒能Running的問題,缺少證書
如等待了半個小時左右還是沒能Running,特別是monitoring這兩個有問題,這個是監(jiān)控用的
那么說明出現(xiàn)問題了,我們來查看一下
kubectl describe pod prometheus-k8s-0 -n kubesphere-monitoring-system
說沒有這個secret-kube-etcd-client-certs這個證書
看一下kubesphere的整個apiserver
ps -ef|grep kube-apiserver
這個apiserver就會打印整個證書位置
說明是有這些證書文件的,但是kubesphere它不知道,它相當于依賴了我們系統(tǒng)里面的
這些證書文件就是在這些位置:
–etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
–etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
–etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
解決方案:把這個命令復制到主節(jié)點運行即可
kubectl -n kubesphere-monitoring-system create secret generic kube-etcd-client-certs --from-file=etcd-client-ca.crt=/etc/kubernetes/pki/etcd/ca.crt --from-file=etcd-client.crt=/etc/kubernetes/pki/apiserver-etcd-client.crt --from-file=etcd-client.key=/etc/kubernetes/pki/apiserver-etcd-client.key
表示這個secret已經創(chuàng)建了
可以用命令查看是否創(chuàng)建成功:
kubectl get secret -A //這個命令的意思就是獲取所有系統(tǒng)里面的secret
只要證書一創(chuàng)建,那么我們這個prometheus很快就可以了
如果還是不行,把這個 prometheus-k8s-0這個pod刪掉
命令:kubectl delete pod prometheus-k8s-0 -n kubesphere-monitoring-system
然后讓它再拉取一個就可以了
再把 prometheus-k8s-1這個pod刪掉,也讓它重新拉取
命令:kubectl delete pod prometheus-k8s-1 -n kubesphere-monitoring-system
那么此時,我們可以看到kubesphere的全部已經搞好了,監(jiān)控也正常了。
總結
以上是生活随笔為你收集整理的kubesphere3.0的安装完整文档的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7 keepalived安装
- 下一篇: helm部署kafka完整记录