From 175f7ccc34cd385d29b42ca015c38ecaccee9ad7 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Mon, 19 Oct 2020 15:03:40 -0400 Subject: [PATCH] Added a README and a Makefile --- Makefile | 10 ++++++ README.md | 36 +++++++++++++++++++ ansible/roles/longhorn/tasks/main.yml | 1 + deploy.sh => bin/deploy.sh | 3 ++ destroy.sh => bin/destroy.sh | 0 .../install-terraform.sh | 0 bin/longhorn-basic-auth.sh | 7 ++++ example-longhorn-basic-auth.sh | 1 - test.env | 4 ++- 9 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 Makefile create mode 100644 README.md rename deploy.sh => bin/deploy.sh (94%) rename destroy.sh => bin/destroy.sh (100%) rename install-terraform.sh => bin/install-terraform.sh (100%) create mode 100644 bin/longhorn-basic-auth.sh delete mode 100644 example-longhorn-basic-auth.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..09db37b --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +deploy: install-terraform run-deploy + +install-terraform: + bash bin/install-terraform.sh + +run-deploy: + bash bin/deploy.sh + +destroy: + bash bin/destroy.sh \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c2cea3f --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# multi-cloud-kubernetes +This is example code for how I deploy a cross cloud Kubernetes cluster to my home openstack, ramnode openstack, and digital ocean. + +# Run +### Set ENVS on test.env +1. DIGITALOCEAN_ACCESS_TOKEN - api token to interact with Digital Ocean. Used by `terraform-code/digitalocean.tf` +RAMNODE_USERNAME - ramnode openstack username. Used by `terraform-code/ramnode.tf` +RAMNODE_PASSWORD - ramnode openstack password. Used by `terraform-code/ramnode.tf` +HOME_USERNAME - home openstack username. Used by `terraform-code/home.tf` +HOME_PASSWORD - home openstack password. Used by `terraform-code/home.tf` +ZEROTIER_NETWORK - zerotier network id. Used by `terraform-code/user-data.sh` +CLOUDFLARE_API - cloudflare api token. Used by `ansible/roles/kubernetes/templates/cloudflare-updater.yaml` to be passed to the cloudflare updater pod. +LONGHORN_USERNAME - any username you want to use for basic auth http for longhorn. Used by `ansible/roles/longhorn/templates/longhorn-ingress.yaml`. Basic auth created by `bin/longhorn-basic-auth.sh` +LONGHORN_PASSWORD - any password you want to use for basic auth http for longhorn. Used by `ansible/roles/longhorn/templates/longhorn-ingress.yaml`. Basic auth created by `bin/longhorn-basic-auth.sh` + +Then run `source test.env` + +### NOTES +1. My personal domain (codywimer.com) is hard coded throughout this project. If replicating, you'll have to change this. +2. My home openstack cloud and ramnodes openstack envs are hard coded in `terraform-code/home.tf` and `terraform-code/ramnode.tf` + +### Deploy +`make deploy` + +This will take your ENV's, pass them to terraform and ansible (see `bin/deploy.sh`) and do the following: +1. Install terraform in this repo +2. Run terraform to deploy cloud resources. Instances will be pre-configured via `terraform-code/user-data.sh` and use a Debian 10 cloud image. +3. Terraform will ouput an ansible inventory to `hosts.cfg` +4. Ansible will be run to deploy Kubernetes via RKE. It will create the `rke` directory where you will find `rke/kube_config_rke-k8s.yaml` to run `kubectl` commands after Kubernetes is deployed. + +### Deploy Notes +1. The `rke` directory contains your kube config file as stated above, a state file rke uses when configuring, `rke/rke-k8s.yaml` which is the rke cluster config, `rke/auth` which is the Kubernetes secret for http basic auth for Longhorn, the `rke/configs` directory which has default resources deployed into Kubernetes, and the `rke/lonhorn` directory which has the Longhorn configs. +2. The Terraform state file is located at `terraform-code/terraform.tfstate` + +### Destroy +`make destroy` \ No newline at end of file diff --git a/ansible/roles/longhorn/tasks/main.yml b/ansible/roles/longhorn/tasks/main.yml index ba5928f..66317ba 100644 --- a/ansible/roles/longhorn/tasks/main.yml +++ b/ansible/roles/longhorn/tasks/main.yml @@ -35,6 +35,7 @@ KUBECONFIG: "{{ rke_directory }}/kube_config_rke-k8s.yaml" delegate_to: localhost run_once: true + ignore_errors: yes - name: Install Longhorn Extras command: kubectl apply -f {{ rke_directory }}/longhorn/ diff --git a/deploy.sh b/bin/deploy.sh similarity index 94% rename from deploy.sh rename to bin/deploy.sh index ba15f09..5475efa 100644 --- a/deploy.sh +++ b/bin/deploy.sh @@ -18,6 +18,9 @@ ${project_dir}/terraform apply -auto-approve -refresh=true \ -var "ramnode_username=${RAMNODE_USERNAME}" \ -var "ramnode_password=${RAMNODE_PASSWORD}" \ -var "do_token=${DIGITALOCEAN_ACCESS_TOKEN}" + +bash ${project_dir}/bin/longhorn-basic-auth.sh + cd ${project_dir}/ansible pipenv sync pipenv run bash run-ansible.sh \ No newline at end of file diff --git a/destroy.sh b/bin/destroy.sh similarity index 100% rename from destroy.sh rename to bin/destroy.sh diff --git a/install-terraform.sh b/bin/install-terraform.sh similarity index 100% rename from install-terraform.sh rename to bin/install-terraform.sh diff --git a/bin/longhorn-basic-auth.sh b/bin/longhorn-basic-auth.sh new file mode 100644 index 0000000..9ae0a6e --- /dev/null +++ b/bin/longhorn-basic-auth.sh @@ -0,0 +1,7 @@ +#!/bin/bash +project_dir=$(git rev-parse --show-toplevel) + +cd ${project_dir} + +mkdir -p ${project_dir}/rke +USER=$LONGHORN_USERNAME; PASSWORD=$LONGHORN_PASSWORD; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> ${project_dir}rke/auth \ No newline at end of file diff --git a/example-longhorn-basic-auth.sh b/example-longhorn-basic-auth.sh deleted file mode 100644 index d67b928..0000000 --- a/example-longhorn-basic-auth.sh +++ /dev/null @@ -1 +0,0 @@ -USER=; PASSWORD=; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> rke/auth \ No newline at end of file diff --git a/test.env b/test.env index fcf7dd5..bb24fc2 100644 --- a/test.env +++ b/test.env @@ -4,4 +4,6 @@ export RAMNODE_PASSWORD= export HOME_USERNAME= export HOME_PASSWORD= export ZEROTIER_NETWORK= -export CLOUDFLARE_API= \ No newline at end of file +export CLOUDFLARE_API= +export LONGHORN_USERNAME= +export LONGHORN_PASSWORD= \ No newline at end of file