Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active March 2, 2023 09:13
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save vfarcic/182473cd7a640520a236d2f0fe51b587 to your computer and use it in GitHub Desktop.
Save vfarcic/182473cd7a640520a236d2f0fe51b587 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/182473cd7a640520a236d2f0fe51b587
################################################
# Multi-Tenant Kubernetes Cluster With Capsule #
# https://youtu.be/H8bzEJN7fj8 #
################################################
# Referenced videos:
# - K3d - How to run Kubernetes cluster locally using Rancher k3s: https://youtu.be/mCesuGk-Fks
#########
# Setup #
#########
git clone https://github.com/vfarcic/capsule-demo
cd capsule-demo
# Please watch https://youtu.be/mCesuGk-Fks if you are not familiar with k3d
# Feel free to use any other Kubernetes platform
k3d cluster create --config k3d.yaml
# If not using k3d, install Ingress in whichever way that works for your Kubernetes distribution
helm repo add clastix https://clastix.github.io/charts
helm upgrade --install \
capsule clastix/capsule \
--namespace capsule-system \
--create-namespace \
--wait
kubectl create namespace not-for-joe
####################
# Creating tenants #
####################
cat tenant.yaml
kubectl apply --filename tenant.yaml
kubectl get tenants
cat create-user.sh
./create-user.sh jdoe team-joe
###################################
# Creating Namespaces as a tenant #
###################################
export KUBECONFIG=jdoe-team-joe.kubeconfig
kubectl create namespace joe
kubectl create namespace team-joe-dev
kubectl create namespace team-joe-prod
kubectl create namespace team-joe-staging
cat tenant.yaml
######################################
# Deploying applications as a tenant #
######################################
cat app.yaml
kubectl --namespace not-for-joe \
apply --filename app.yaml
kubectl --namespace not-for-joe get pods
kubectl delete namespace not-for-joe
kubectl --namespace joe \
apply --filename app.yaml
kubectl --namespace joe get all
kubectl --namespace joe get rolebindings
kubectl get namespaces
###########
# Destroy #
###########
k3d cluster delete devops-toolkit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment