Vig*_*mar 10 kubernetes google-kubernetes-engine kubernetes-dashboard kubernetes-pod
我们使用以下命令创建了 kubernetes 仪表板。
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml
kubectl patch svc -n kubernetes-dashboard kubernetes-dashboard --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
Run Code Online (Sandbox Code Playgroud)
创建了如下所示的仪表板-adminuser.yaml 文件。
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kubernetes-dashboard
Run Code Online (Sandbox Code Playgroud)
创建了 ClusterRoleBinding.yaml 文件,如下所示
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: kubernetes-dashboard
Run Code Online (Sandbox Code Playgroud)
然后运行以下命令,最后我们得到了登录仪表板的令牌。
kubectl apply -f dashboard-adminuser.yaml
kubectl apply -f ClusterRoleBinding.yaml
kubectl -n kubernetes-dashboard create token admin-user
Run Code Online (Sandbox Code Playgroud)
但问题是我们生成的令牌在一小时后就过期了。如果仪表板注销,我们将无法再次使用相同的令牌。
那么我们可以创建一个没有到期日或至少 6 个月的代币吗?
创建长期使用令牌的命令/过程是什么?
另一件事是,现在我们可以在外部访问 kubernetes 仪表板,如下所示。
https://服务器 IP 地址:PORT_NUMBER
现在我们想要使用我们的网站 URL 打开 kubernetes 仪表板,如下所示,它应该自动登录到仪表板。
https://my-domain-name.com/kubernetes-dashboard/{kubernetes-dashboard-goto-url}
你可以设置--duration=0s:
--duration=0s:
Requested lifetime of the issued token. The server may return a token with a longer or shorter lifetime.
Run Code Online (Sandbox Code Playgroud)
所以这应该有效
kubectl -n kubernetes-dashboard create token admin-user --duration=times
Run Code Online (Sandbox Code Playgroud)
你可以检查进一步的选项
kubectl create token --help
Run Code Online (Sandbox Code Playgroud)
玩弄了令牌后,似乎最大过期时间是 720 小时。
kubectl create token default --duration=488h --output yaml
Run Code Online (Sandbox Code Playgroud)
输出显示
kind: TokenRequest
metadata:
creationTimestamp: null
spec:
audiences:
- https://container.googleapis.com/v1/projects/test/clusters/test
boundObjectRef: null
expirationSeconds: **172800**
status:
expirationTimestamp: "2022-08-21T12:37:02Z"
token: eyJhbGciOiJSUzI1N....
Run Code Online (Sandbox Code Playgroud)
因此,另一个选择是使用 kubeconfig,因为仪表板也接受配置。
归档时间: |
|
查看次数: |
11901 次 |
最近记录: |