Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Kubectl Create and Get Token Bash
sudo su docker
minikube kubectl -- apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
name: demo-account
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: demo-account
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: demo-account-admin
subjects:
- kind: ServiceAccount
name: demo-account
namespace: default
EOF
minikube kubectl -- apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: demo-account-secret
annotations:
kubernetes.io/service-account.name: demo-account
type: kubernetes.io/service-account-token
EOF
export TOKEN=$(minikube kubectl -- get serviceaccount demo-account -o=jsonpath='{.secrets[0].name}' | xargs minikube kubectl -- get secret -ojsonpath='{.data.token}' | base64 --decode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment