Skip to content

Instantly share code, notes, and snippets.

@dwburke
Created August 3, 2017 18:34
Show Gist options
  • Save dwburke/5ae9f128591386419cb63496c3814a15 to your computer and use it in GitHub Desktop.
Save dwburke/5ae9f128591386419cb63496c3814a15 to your computer and use it in GitHub Desktop.
Create kubernetes service account
#!/bin/bash
set -eu
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Usage: $0 <username>"
user=$1
# needs to be done service-side if you don't already have access
kubectl create sa ${user}
secret=`kubectl get secrets | grep ${user} | awk '{print $1}'`
echo ${secret}
token=`kubectl describe secret ${secret}|grep token:|awk '{print $2}'`
echo ; echo ${token}; echo
# give admin access:
#kubectl edit clusterrolebinding cluster-admin
#
#- kind: ServiceAccount
# name: <user>
# namespace: default
#
#locally:
#cluster_name=foo
#kubectl config set-credentials ${cluster_name} --token='${token}'
#kubectl config set-cluster ${cluster_name} --insecure-skip-tls-verify=true --server=https://<ip>:<port>
#kubectl config set-context ${cluster_name} --user=${cluster_name} --namespace=default --cluster=${cluster_name}
#kubectl config use-context ${cluster_name}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment