一拜效、windows系統(tǒng)使用kubectl
1获枝、windows安裝Chocolatey
參考文章Installing Chocolatey
管理員運行 powershell
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
image.png
2循签、安裝kubectl
參考文章Kubernetes Command Line Interface (CLI)
1.18.2
choco install kubernetes-cli
image.png
3姚淆、config文件
注意到在之前安裝k8s有如下步驟
image.png
所以我們把這個
admin.conf
文件下載到本地勤哗,拷貝到
C:\Users\your user name\.kube\
目錄下
3于样、驗證
-
kubectl config get-contexts
image.png -
kubectl get nodes
image.png
猜測是因為虛擬機的時間跟本地不同
image.png - 修復
timedatectl set-local-rtc 1
timedatectl set-timezone Asia/Shanghai
yum -y install ntp
#通過阿里云時間服務器校準時間
ntpdate ntp1.aliyun.com
#時間信息寫入硬件
hwclock -w
image.png
-
重試
image.png
二疏叨、安裝Dashboard
0、參考文章
- kubernetes.io 網頁界面 (Dashboard)
- https://github.com/kubernetes/dashboard
- Creating sample user
- Kubernetes Dashboard 安裝與使用
- How To Install Kubernetes Dashboard with NodePort
- Kubernetes的三種外部訪問方式:NodePort穿剖、LoadBalancer 和 Ingress
- 淺析從外部訪問 Kubernetes 集群中應用的幾種方式
1蚤蔓、安裝
- 下載文件到本地
https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.3/aio/deploy/recommended.yaml
- 安裝
kubectl apply -f .\kubernetes-dashboard.yaml
image.png
- 查看運行情況
kubectl get pods -n kubernetes-dashboard
image.png
- 啟用代理
kubectl proxy
image.png
- 本地主機訪問
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
可以看到登錄界面
image.png
2、授權
- 新建文件
auth.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
---
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: kubernetes-dashboard
- kubectl 應用文件
kubectl apply -f .\auth.yaml
image.png
kubectl get deployment -n kubernetes-dashboard
image.png
- 獲取token
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | sls admin-user | ForEach-Object { $_ -Split '\s+' } | Select -First 1)
image.png
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
- 復制
token
串糊余,粘貼到登錄界面即可
3.1秀又、改為NodePort
image.png
kubectl edit service kubernetes-dashboard -n kubernetes-dashboard
將上圖的值改為NodePort
,保存
image.png
kubectl get svc --all-namespaces
image.png
3.2贬芥、改為NodePort
-- 另一種方式
- 回滾之前的操作
kubectl delete -f .\auth.yaml
kubectl delete -f .\kubernetes-dashboard.yaml
- 修改
kubernetes-dashboard.yaml
Service
下添加type: NodePort
image.png - 部署
kubectl apply -f .\kubernetes-dashboard.yaml
kubectl get deployments -n kubernetes-dashboard
kubectl get pods -n kubernetes-dashboard
kubectl get service -n kubernetes-dashboard
image.png
kubectl apply -f .\auth.yaml
image.png
- 訪問
使用任意一個node節(jié)點【centos-master或centos-node】的ip+port即可訪問
kubectl get svc -n kubernetes-dashboard
image.png
https://192.168.32.129:30667
https://192.168.32.131:30667
經測試吐辙,谷歌瀏覽器無法訪問,edge可以
復制token
蘸劈,登錄
kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | sls admin-user | ForEach-Object { $_ -Split '\s+' } | Select -First 1)
image.png