post-image

Installing a Local Kubernetes Cluster with Helm and Terraform


The time has come to start a new project, which means a lot of internal testing (right?). Hosting costs can get a bit rough, especially if you’re testing and constantly pulling down and building up new infrastructure. Not to fear, Docker Desktop is here!

In this tutorial, we’ll explain how to install Docker Desktop with Kubernetes, Helm, and Terraform to handle automated deployment, scaling, and containerizing of your applications.

Windows


  1. Install Docker Desktop
  2. From Docker Desktop, go to Settings -> Kubernetes and select “Enable Kubernetes”.
    • This will install Kubernetes on your machine and can take a while.
  3. Install Helm
    • It’s recommended to install helm with Chocolatey
  4. Install terraform v0.11.14 by selecting the appropriate download.
    • IMPORTANT! We are currently using an older version of Terraform. This will change in the future.
    • After downloading the appropriate release of Terraform, unzip the archive and move terraform to an appropriate location such as C:\terraform.
    • Now, open Control Panel -> System -> Advanced system settings -> Advanced -> Environment Variables…
    • Select Path from System Variables, then hit the Edit button.
    • Hit the New button and enter the address of your terraform file, then hit Okay.
      • For example, if you put it in the same place as above, you would enter C:\terraform
    • Open a fresh Command Prompt and type terraform -v. This should output Terraform v0.11.14 if you have the correct version installed. It will also prompt you about updating, but don’t worry about that right now.

Deploying to a Local Cluster


Alrighty. Now this next part assumes you’ve already got build scripts written. Don’t worry, we’ve got more coming on that soon!

After you’ve pulled down your repo, you’ll need to do the following

  1. Edit C:\Windows\System32\drivers\etc\hosts as follows.

    • You will need to run an editor such as Notepad in Administrator mode to do this

    Copy and paste the following to the bottom of your hosts file

   # BEGIN section for <your project>
   127.0.0.1       sts-local.[your_domain].com
   # END section for <your project>
  1. Open Powershell as an administrator and run the following commands from inside your project’s directory:
   cd backend/build
   ./build.ps1 -env=local -target=Build
   ./build.ps1 -env=local -target=Helm
  1. Open a new Command Prompt or Powershell and run the following commands from inside your project’s directory:
	cd backend/build
	helm serve --repo-path ./helm-packages
  1. Back in Powershell from Step 3, run the following commands:
	./build.ps1 -env=local -target=Plan
	./build.ps1 -env=local -target=Apply
  1. Check to see if it was successful by navigating to http://sts-local.[your_domain].com/.well-known/openid-configuration in your favorite browser
    • If you get an error after running ./build.ps1 -evn=local -target=Apply, you may need to restart your Docker Desktop.
    • In a Command Prompt, enter kubectl get pods. If this comes up blank or gives you an error, try restarting docker and repeating Steps 3 and 5.

MACOS and Linux


  1. Install Docker Desktop
  2. From Docker Desktop, go to Settings -> Kubernetes and select “Enable Kubernetes”.
    • This will install Kubernetes on your machine and can take a while.
  3. Install Helm
  4. Install terraform v0.11.14 by selecting the appropriate download.
    • IMPORTANT! We are currently using an older version of Terraform. This will change in the future.
    • After downloading the appropriate release of Terraform, unzip the archive.
    • In your terminal, run the following command: `cp $Home/Downloads/terraform /usr/local/bin/
      • This should move terraform to a place in your path
    • Type terraform -v. This should output Terraform v0.11.14 if you have the correct version installed. It will also prompt you about updating, but don’t worry about that right now.

Deploying to a Local Cluster


  1. Edit etc/hosts as follows.
    • In your terminal type sudo vi ~/../../etc/hosts
    • Type i to start Insert Mode
    • Copy and paste the below code to the bottom of your hosts file, then hit Esc then :wq to save and exit Vim.
   # BEGIN section for <your project>
   127.0.0.1       sts-local.[your_domain].com
   # END section for <your project>
  1. In your terminal, run the following commands from inside your project’s directory:
   cd backend/build
   build.sh -env=local -target=Build
   build.sh -env=local -target=Helm
  1. Open a new terminal and run the following commands from inside your project’s directory:
	cd backend/build
	helm serve --repo-path ./helm-packages
  1. Back in terminal from Step 3, run the following commands:
	build.sh -env=local -target=Plan
	build.sh -env=local -target=Apply
  1. Check to see if it was successful by navigating to http://sts-local.[your_domain].com/.well-known/openid-configuration in your favorite browser
    • If you get an error after running build.sh -evn=local -target=Apply, you may need to restart your Docker Desktop.
    • In a Command Prompt, enter kubectl get pods. If this comes up blank or gives you an error, try restarting docker and repeating Steps 3 and 5.

Back to blog