Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active September 18, 2023 23:59
Show Gist options
  • Save vfarcic/2dbb2f8683e661eaf0446f10b6974efb to your computer and use it in GitHub Desktop.
Save vfarcic/2dbb2f8683e661eaf0446f10b6974efb to your computer and use it in GitHub Desktop.

Revisions

  1. vfarcic revised this gist Jun 25, 2021. 1 changed file with 10 additions and 8 deletions.
    18 changes: 10 additions & 8 deletions 094-vcluster.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,9 @@
    ###########################################################
    # How To Create Virtual Kubernetes Clusters With vcluster #
    # https://youtu.be/JqBjpvp268Y #
    ###########################################################
    # 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
    @@ -48,9 +50,9 @@ vcluster --namespace a-team \
    create a-team \
    --extra-values helm-values.yaml

    ################################################
    # Creating a connection to the virtual cluster #
    ################################################
    #####################################
    # Connecting to the virtual cluster #
    #####################################

    kubectl --namespace a-team \
    get all
    @@ -69,7 +71,7 @@ kubectl get namespace
    kubectl --namespace kube-system get pods

    #################################################
    # Deploying applications to the virtual cluster #
    # Deploying applications in the virtual cluster #
    #################################################

    cat app.yaml
  2. vfarcic created this gist Jun 25, 2021.
    126 changes: 126 additions & 0 deletions 094-vcluster.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,126 @@
    ###########################################################
    # How To Create Virtual Kubernetes Clusters With vcluster #
    # 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

    ################################################
    # Creating a connection 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 to 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