阿里云k8s v1.23.0如何用网页访问
时间: 2024-04-06 11:28:42 浏览: 202
阿里云Kubernetes集群默认不开启Kubernetes Dashboard,您需要手动开启,以下是在阿里云Kubernetes v1.23.0中使用Web界面的步骤:
1. 安装Kubernetes Dashboard。
```bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.1/aio/deploy/recommended.yaml
```
2. 创建Kubernetes Dashboard Service Account和ClusterRoleBinding。
```bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.1/aio/deploy/recommended.yaml
```
3. 修改Kubernetes Dashboard Service Type为NodePort。
```bash
kubectl -n kubernetes-dashboard edit service kubernetes-dashboard
```
将Service Type修改为NodePort,并添加NodePort端口号,如:
```yaml
apiVersion: v1
kind: Service
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"k8s-app":"kubernetes-dashboard"},"name":"kubernetes-dashboard","namespace":"kubernetes-dashboard"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
creationTimestamp: "2022-01-04T05:20:19Z"
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kubernetes-dashboard
resourceVersion: "14272"
selfLink: /api/v1/namespaces/kubernetes-dashboard/services/kubernetes-dashboard
uid: 6d4d7a0d-e270-4a98-9b0f-4f0b4d6f2eb0
spec:
clusterIP: 172.20.33.97
externalTrafficPolicy: Cluster
ports:
- nodePort: 32000 # 添加NodePort端口号
port: 443
protocol: TCP
targetPort: 8443
selector:
k8s-app: kubernetes-dashboard
sessionAffinity: None
type: NodePort # 修改Service Type为NodePort
status:
loadBalancer: {}
```
4. 获取Kubernetes Dashboard访问链接。
```bash
kubectl -n kubernetes-dashboard get service kubernetes-dashboard
```
将输出信息中的NodePort端口号记录下来,然后使用以下URL访问Kubernetes Web界面:
```bash
https://<master-ip>:<nodeport>
```
其中,`<master-ip>`为您的Kubernetes集群Master节点IP,`<nodeport>`为上一步记录的NodePort端口号。
您将看到一个登录页面,选择“Token”身份验证并输入以下命令以获取令牌:
```bash
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep service-controller-token | awk '{print $1}')
```
将令牌复制到登录页面中并点击“登录”按钮即可访问Kubernetes Web界面。
阅读全文