Skip to content

Instantly share code, notes, and snippets.

@EarthmanT
Created August 29, 2021 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EarthmanT/d478c2f1bb63b3211a243a036fb2fa22 to your computer and use it in GitHub Desktop.
Save EarthmanT/d478c2f1bb63b3211a243a036fb2fa22 to your computer and use it in GitHub Desktop.
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