'Please enter Username for - ServiceAccount deployment

I get Please enter Username when I try to deploy with a ServiceAccount, even I have set ClusterRole bindings - do you know why?

kubectl:

kubectl apply -f deployment.yaml

Role & binding:

kubectl create clusterrole tutorial-role \
               --verb=get,list,watch,create,update,patch,delete \
               --resource=deployments


kubectl create clusterrolebinding tutorial-binding \
             --clusterrole=tutorial-role \
             --serviceaccount=default:tutorial-service

Create config user:

TOKEN=$(kubectl describe secrets "$(kubectl describe serviceaccount tutorial-service | grep -i Tokens | awk '{print $2}')" | grep token: | awk '{print $2}')
kubectl config set-credentials tutorialuser --token=$TOKEN
kubectl config set-context sausercontext --cluster=<my-cluster> --user=tutorialuser
kubectl config use-context sausercontext --namespace=default

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: leeroy-web
  labels:
    app: leeroy-web
spec:
  replicas: 1
  selector:
    matchLabels:
      app: leeroy-web
  template:
    metadata:
      labels:
        app: leeroy-web
    spec:
      containers:
        - name: leeroy-web
          image: gcr.io/appsyouwear/leeroy-web
          ports:
            - containerPort: 8080

Info:

kubernetes % kubectl -v=8 apply -f deployment.yaml   
I0111 13:57:05.950317   63261 loader.go:359] Config loaded from file /Users/username/.kube/config
Please enter Username:


Solution 1:[1]

Your Kubeconfig file is munged.Either you don't have an user in the contexts section or you don't have an user in the users section. contexts and users section of your kubeconfig should look like below.

contexts:
- context:
    cluster: kubernetes
    user: tutorialuser
  name: sausercontext


users:
- name: tutorialuser
  user: 
    token: <removed>

Solution 2:[2]

if you are using kops then you can fix this by entering below command

kops export kubecfg --admin

or you can try this

kops update cluster ${NAME} --yes --state ${KOPS_STATE_STORE} --admin

or by exporting KOPS_STATE_STORE

export KOPS_STATE_STORE=s3://test-new-store

if you have not created s3 bucket then follow the below commands to create

aws s3 mb s3://test-new-store --region ap-south-1

aws s3api put-bucket-versioning --bucket test-new-store --versioning-configuration Status=Enabled

export KOPS_STATE_STORE=s3://test-new-store

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 yogesh cl