3

I have installed Kubernetes using AWS Minikube scripts - https://github.com/scholzj/aws-minikube

After installation I am trying to run

kubectl proxy

But I am getting this

https:kubernetes-dashboard:\" is forbidden: User \"system:anonymous\" cannot get services/proxy in the namespace \"kube-system\"

I am not even able to list pods because I do not have valid tokens with system.master role. I have no idea how I can create a user or token and authenticate when there is no admin user present on the system yet.

Can you please explain to me?

  • Out of interest, why do this manually using scripts rather than use EKS? – Caledonia91 Oct 1 '18 at 9:05
  • I needed just one-node instance, not full cluster. Furthermore I have not known that something like EKS exists. – Koss645 Oct 2 '18 at 6:13
2

how we can extract the certificates from the kubeconfig file:

  1. Locate your kubeconfig or config file which you use to run kubectl commands. If you have used my Vagrant file above, you can find it on /etc/kubernetes/admin.conf
  2. You need to export a single file (.p12) with the following two certificates: the client-certificate-data, and the client-key-data. My example runs the command on /home/vagrant. If you run this command on macOS, be sure to change the base64 -d to base64 -D

    $ grep 'client-certificate-data' ~/.kube/config | head -n 1 | awk '{print $2}' | base64 -d >> kubecfg.crt
    
    
    $ grep 'client-key-data' ~/.kube/config | head -n 1 | awk '{print $2}' | base64 -d >> kubecfg.key
    
    
    $ openssl pkcs12 -export -clcerts -inkey kubecfg.key -in kubecfg.crt -out kubecfg.p12
    
  3. Import the kubecfg.p12 certificate, reopen your browser, and visit the Kubernetes Dashboard URL. Accept any warning and you should see the authentication page. You can skip the login and check you are not able to perform any task.

  4. The following steps have been copied from the Kubernetes Dashboard wiki page (Creating-sample-user)

        1- Create service account
    
            cat <<EOF | kubectl create -f -
            apiVersion: v1
            kind: ServiceAccount
            metadata:
              name: admin-user
              namespace: kube-system
            EOF
            >>
    
        2- Create ClusterRoleBinding
    
            cat <<EOF | kubectl create -f -
            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: kube-system
            EOF
            >>
    
        3- Get the Bearer Token. Once you run the following command, copy the token value which you will use on the following step.
    
            $ kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
    
    
        4- Come back to your browser and choose token on the login page. You will need to paste the token value you have copied on the previous step.
    5- Click “SIGN IN” and you should be able to see your Kubernetes Dashboard fully operational.
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.