<p>We have created kubernetes dashboard using below command.</p>
<pre><code>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 '[{&quot;op&quot;:&quot;replace&quot;,&quot;path&quot;:&quot;/spec/type&quot;,&quot;value&quot;:&quot;NodePort&quot;}]'
</code></pre>
<p>created dashboard-adminuser.yaml file like below.</p>
<pre><code>apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
</code></pre>
<p>Created ClusterRoleBinding.yaml file like below</p>
<pre><code>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
</code></pre>
<p>And then run the below command at the end we got a token to login dashboard.</p>
<pre><code>kubectl apply -f dashboard-adminuser.yaml
kubectl apply -f ClusterRoleBinding.yaml
kubectl -n kubernetes-dashboard create token admin-user
</code></pre>
<p>But the problem is the token which we generated got expired in one hour. We couldn't able to use the same token again, if dashboard logged out.</p>
<p>So can we create a token without expiry or at least minimum 6 months?</p>
<p>What is the command/procedure to create a token for long time use?</p>
<p>And one more thing is that can now we are accessing kubernetes dashboard like below in outside.</p>
<p>https://server_ip_address:PORT_NUMBER</p>
<p>Now we want to open the kubernetes dashboard using our website URL like below and it should login automatically to the dashboard.</p>
<p><a href="https://my-domain-name.com/kubernetes-dashboard/%7Bkubernetes-dashboard-goto-url%7D" rel="noreferrer">https://my-domain-name.com/kubernetes-dashboard/{kubernetes-dashboard-goto-url}</a></p>

Vignesh Kumar
<p>you can set <code>--duration=0s:</code></p>
<pre><code>    --duration=0s:
    Requested lifetime of the issued token. The server may return a token with a longer or shorter lifetime.
</code></pre>
<p>so this should work</p>
<pre><code>kubectl -n kubernetes-dashboard create token admin-user --duration=times
</code></pre>
<p>you can check the further option</p>
<pre><code>kubectl  create token --help
</code></pre>
<p><a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#-em-token-em-" rel="noreferrer">kubectl-commands--toke</a></p>
<p>After play around with token, it seems like the maximum expiration is 720h.</p>
<pre><code>kubectl create token default --duration=488h --output yaml
</code></pre>
<p>and the output shows</p>
<pre><code>kind: TokenRequest
metadata:
  creationTimestamp: null
spec:
  audiences:
  - https://container.googleapis.com/v1/projects/test/clusters/test
  boundObjectRef: null
  expirationSeconds: **172800**
status:
  expirationTimestamp: &quot;2022-08-21T12:37:02Z&quot;
  token: eyJhbGciOiJSUzI1N....
</code></pre>
<p>So the other option is to go with kubeconfig as the dashboard also accepts config.</p>
<p><a href="https://github.com/kubernetes/dashboard/blob/v2.0.0/docs/user/access-control/README.md#kubeconfig" rel="noreferrer">dashboard-auth-kubeconfig</a></p>
