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:
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>