Skip to content

Instantly share code, notes, and snippets.

@npearce
Last active September 30, 2020 20:58
Show Gist options
  • Save npearce/05922cf08aa500f0dc8ef8d27d1188a5 to your computer and use it in GitHub Desktop.
Save npearce/05922cf08aa500f0dc8ef8d27d1188a5 to your computer and use it in GitHub Desktop.

Revisions

  1. npearce revised this gist Sep 30, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Vagrantfile
    Original file line number Diff line number Diff line change
    @@ -39,6 +39,7 @@ Vagrant.configure("2") do |config|
    # Specify your hostname if you like
    # k8s1.vm.hostname = "k8s1"
    k8s1.vm.box = "bento/ubuntu-20.04"
    k8s1.vm.provision "shell", inline: "swapoff -a"
    k8s1.vm.network "private_network", type: "dhcp"
    # k8s1.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true
    k8s1.vm.provision "docker"
    @@ -56,6 +57,7 @@ Vagrant.configure("2") do |config|
    # Specify your hostname if you like
    # k8s2.vm.hostname = "k8s2"
    k8s2.vm.box = "bento/ubuntu-20.04"
    k8s2.vm.provision "shell", inline: "swapoff -a"
    k8s2.vm.network "private_network", type: "dhcp"
    # k8s2.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true
    k8s2.vm.provision "docker"
  2. npearce revised this gist Sep 30, 2020. 2 changed files with 34 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions consul-values-k8s1.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    global:
    domain: consul
    datacenter: k8sdc1

    server:
    replicas: 3
    bootstrapExpect: 3

    client:
    enabled: true
    grpc: true

    ui:
    enabled: true

    connectInject:
    enabled: true
    17 changes: 17 additions & 0 deletions consul-values-k8s3.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    global:
    domain: consul
    datacenter: k8sdc2

    server:
    replicas: 3
    bootstrapExpect: 3

    client:
    enabled: true
    grpc: true

    ui:
    enabled: true

    connectInject:
    enabled: true
  3. npearce renamed this gist Sep 30, 2020. 1 changed file with 14 additions and 2 deletions.
    16 changes: 14 additions & 2 deletions finish_install.sh → Lab_k8s_MultiCluster.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,15 @@
    #!/bin/sh
    # Two k8s Cluserts w/ Consul in Vagrant

    This will create 2 virtualbox VM's each with full (not Minikube) single node k8s installs:

    `vagrant up`

    ## Complete the install in each VM

    Perform the following for both k8s1 and k8s2

    ```sh
    vagrant ssh k8s1

    kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
    kubectl taint nodes --all node-role.kubernetes.io/master-
    @@ -8,4 +19,5 @@ chmod 700 get_helm.sh
    ./get_helm.sh
    helm repo add hashicorp https://helm.releases.hashicorp.com
    helm search repo hashicorp/consul
    helm install consul hashicorp/consul --set global.name=consul
    helm install consul hashicorp/consul --set global.name=consul
    ```
  4. npearce revised this gist Sep 30, 2020. 2 changed files with 11 additions and 0 deletions.
    File renamed without changes.
    11 changes: 11 additions & 0 deletions finish_install.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #!/bin/sh

    kubectl apply -f https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')
    kubectl taint nodes --all node-role.kubernetes.io/master-

    curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
    chmod 700 get_helm.sh
    ./get_helm.sh
    helm repo add hashicorp https://helm.releases.hashicorp.com
    helm search repo hashicorp/consul
    helm install consul hashicorp/consul --set global.name=consul
  5. npearce created this gist Sep 30, 2020.
    68 changes: 68 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    # -*- mode: ruby -*-
    # vi: set ft=ruby :

    # This script to install Kubernetes will get executed after we have provisioned the box
    $script = <<-SCRIPT
    # Install kubernetes
    apt-get update && apt-get install -y apt-transport-https
    curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
    cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
    deb http://apt.kubernetes.io/ kubernetes-xenial main
    EOF
    apt-get update
    apt-get install -y kubelet kubeadm kubectl
    # kubelet requires swap off
    swapoff -a
    # keep swap off after reboot
    sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
    # Get the IP address that VirtualBox has given this VM
    IPADDR=`ip -4 address show dev eth1 | grep inet | awk '{print $2}' | cut -f1 -d/`
    echo This VM has IP address $IPADDR
    # Writing the IP address to a file in the shared folder
    echo $IPADDR > /vagrant/ip-address.txt
    # Set up Kubernetes
    NODENAME=$(hostname -s)
    kubeadm init --apiserver-cert-extra-sans=$IPADDR --node-name $NODENAME
    # Set up admin creds for the vagrant user
    echo Copying credentials to /home/vagrant...
    sudo --user=vagrant mkdir -p /home/vagrant/.kube
    cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
    chown $(id -u vagrant):$(id -g vagrant) /home/vagrant/.kube/config
    SCRIPT

    Vagrant.configure("2") do |config|
    config.vm.define :k8s1 do |k8s1|
    k8s1.vm.provider "virtualbox" do |v|
    v.memory = 16384
    v.cpus = 2
    end
    # Specify your hostname if you like
    # k8s1.vm.hostname = "k8s1"
    k8s1.vm.box = "bento/ubuntu-20.04"
    k8s1.vm.network "private_network", type: "dhcp"
    # k8s1.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true
    k8s1.vm.provision "docker"
    # Specify the shared folder mounted from the host if you like
    # By default you get "." synced as "/vagrant"
    # k8s1.vm.synced_folder ".", "/folder"
    k8s1.vm.provision "shell", inline: $script
    end

    config.vm.define :k8s2 do |k8s2|
    k8s2.vm.provider "virtualbox" do |v|
    v.memory = 16384
    v.cpus = 2
    end
    # Specify your hostname if you like
    # k8s2.vm.hostname = "k8s2"
    k8s2.vm.box = "bento/ubuntu-20.04"
    k8s2.vm.network "private_network", type: "dhcp"
    # k8s2.vm.network "forwarded_port", guest: 10102, host: 10102, autocorrect: true
    k8s2.vm.provision "docker"
    # Specify the shared folder mounted from the host if you like
    # By default you get "." synced as "/vagrant"
    # k8s2.vm.synced_folder ".", "/folder"
    k8s2.vm.provision "shell", inline: $script
    end

    end