Skip to content

Instantly share code, notes, and snippets.

@thanandorn
Last active October 12, 2018 08:46
Show Gist options
  • Save thanandorn/8c7d1678a13d7bf33920cb98e4a72982 to your computer and use it in GitHub Desktop.
Save thanandorn/8c7d1678a13d7bf33920cb98e4a72982 to your computer and use it in GitHub Desktop.
Tiller per namespaces on GKE

tiller.yaml

---
kind: Namespace
apiVersion: v1
metadata:
  name: NAMESPACE
  labels:
    name: NAMESPACE
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: NAMESPACE

role-tiller.yaml

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: tiller-manager
  namespace: NAMESPACE
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: tiller-binding
  namespace: NAMESPACE
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: NAMESPACE
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io

run.sh

GCP_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)" )
export KUBECONFIG=/circleci/.kube/config.all
for ctx in $(kubectl config get-contexts -o name); do
  for NS in infra web backend monitoring ; do
    if helm --kube-context="${ctx}" ls --tiller-namespace=${NS} ; then
      helm --kube-context="${ctx}" init --service-account tiller --tiller-namespace $NS --client-only
    else
      kubectl --context="${ctx}" apply -f <(sed -e "s/NAMESPACE/${NS}/" k8s/tiller/tiller.yaml)
      kubectl --context="${ctx}" -n ${NS} create clusterrolebinding user-admin --clusterrole=cluster-admin --user=${GCP_ACCOUNT}
      kubectl --context="${ctx}" apply -f <(sed -e "s/NAMESPACE/${NS}/" k8s/tiller/role-tiller.yaml)
      kubectl --context="${ctx}" -n ${NS} delete clusterrolebinding user-admin
      helm --kube-context="${ctx}" init --service-account tiller --tiller-namespace $NS --wait
    fi
  done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment