Skip to content

Instantly share code, notes, and snippets.

@includeamin
Created November 12, 2019 14:20
Show Gist options
  • Save includeamin/ac2230f9737405b7741fcee3e47e033f to your computer and use it in GitHub Desktop.
Save includeamin/ac2230f9737405b7741fcee3e47e033f to your computer and use it in GitHub Desktop.
access to kuberntes dashboard from public ip

Access to Kuberntes dashboard public ip

  1. install kuberntes dashboard

    kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
  2. Edit kubernetes service

    kubectl -n kube-system edit service kubernetes-dashboard
    # Please edit the object below. Lines beginning with a '#' will be ignored,
    # and an empty file will abort the edit. If an error occurs while saving this file will be
    # reopened with the relevant failures.
    #
    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":"kube-system"},"spec":{"ports":[{"port":443,"targetPort":8443}],"selector":{"k8s-app":"kubernetes-dashboard"}}}
      creationTimestamp: "2019-11-12T08:28:58Z"
      labels:
        k8s-app: kubernetes-dashboard
      name: kubernetes-dashboard
      namespace: kube-system
      resourceVersion: "16616648"
      selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
      uid: ***
    
    spec:
      clusterIP: ****
    
      externalTrafficPolicy: Cluster
      ports:
      - nodePort: 31025
        port: 443
        protocol: TCP
        targetPort: 8443
      selector:
        k8s-app: kubernetes-dashboard
      sessionAffinity: None
      type: NodePort # change ClusterIp to NodePort
    
    status:
      loadBalancer: {}
     
  3. Now you can open this link in your browser

    https://master_server_ip:node_port_ip
    
  4. Login to kuberntes with Token

    1. Find kubernetes dashboard token secret
     kubectl get secret -n kube-system
     
    output:
    .
    .
    .
     kubernetes-dashboard-token-vdh5j
    .
    .
    .
    1. Copy token

      sudo kubectl describe secret -n kube-system kubernetes-dashboard-token-vdh5j
        #output
       Name: kubernetes-dashboard-token-vdh5j
       Namespace: kube-system
       Labels: <none>
       Annotations: kubernetes.io/service-account.name: kubernetes- dashboard
       kubernetes.io/service-account.uid: 1332793e-f1d2-438a-af36-34a49c6b9bba
       Type: kubernetes.io/service-account-token
       Data
       ====
       ca.crt: 1025 bytes
       namespace: 11 bytes
       token: ******

    Now you can login to your dashboard and enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment