Last active
September 18, 2023 23:59
-
-
Save vfarcic/2dbb2f8683e661eaf0446f10b6974efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://gist.github.com/2dbb2f8683e661eaf0446f10b6974efb | |
################################################################### | |
# How To Create Virtual Kubernetes Clusters With vcluster By loft # | |
# https://youtu.be/JqBjpvp268Y # | |
################################################################### | |
# Referenced videos: | |
# - Multi-Tenant Kubernetes Cluster With Capsule: https://youtu.be/H8bzEJN7fj8 | |
######### | |
# Setup # | |
######### | |
# Create a Kuberentes cluster | |
git clone https://github.com/vfarcic/vcluster-demo | |
cd vcluster-demo | |
# Install the CLI from https://www.vcluster.com/docs/getting-started/setup#download-vcluster-cli | |
############################# | |
# Creating virtual clusters # | |
############################# | |
kubectl create namespace a-team | |
cat service.yaml | |
kubectl --namespace a-team \ | |
apply --filename service.yaml | |
# If NOT EKS | |
export VCLUSER_IP=$(kubectl --namespace a-team \ | |
get service a-team-cluster \ | |
--output jsonpath="{.status.loadBalancer.ingress[0].ip}") | |
# If EKS | |
export VCLUSER_IP=$(kubectl --namespace a-team \ | |
get service a-team-cluster \ | |
--output jsonpath="{.status.loadBalancer.ingress[0].hostname}") | |
echo $VCLUSER_IP | |
# Open helm-values.yaml and replace `syncer.extraArgs[0].--tls-san' value with the output of the previous command | |
# It could be Helm or YAML as well | |
vcluster --namespace a-team \ | |
create a-team \ | |
--extra-values helm-values.yaml | |
##################################### | |
# Connecting to the virtual cluster # | |
##################################### | |
kubectl --namespace a-team \ | |
get all | |
# Switch to Ingress | |
vcluster --namespace a-team \ | |
connect a-team \ | |
--server https://$VCLUSER_IP | |
cat kubeconfig.yaml | |
export KUBECONFIG=$PWD/kubeconfig.yaml | |
kubectl get namespace | |
kubectl --namespace kube-system get pods | |
################################################# | |
# Deploying applications in the virtual cluster # | |
################################################# | |
cat app.yaml | |
kubectl create namespace production | |
kubectl --namespace production \ | |
apply --filename app.yaml | |
kubectl get namespaces | |
kubectl --namespace a-team \ | |
get deployments | |
kubectl --namespace a-team \ | |
get pods | |
kubectl --namespace a-team \ | |
get services | |
kubectl --namespace a-team \ | |
get ingresses | |
kubectl get nodes | |
################################# | |
# Exploring the virtual cluster # | |
################################# | |
unset KUBECONFIG | |
kubectl get namespaces | |
kubectl --namespace a-team \ | |
get deployments | |
kubectl --namespace a-team \ | |
get pods | |
kubectl --namespace a-team \ | |
get services | |
kubectl --namespace a-team \ | |
get ingresses | |
kubectl get nodes | |
################################## | |
# Destroying the virtual cluster # | |
################################## | |
vcluster --namespace a-team delete a-team | |
kubectl --namespace a-team get pods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment