Infrastructure 2021-04-06

Building a Kubernetes Environment with Terraform and Ansible

A journey of setting up a Kubernetes environment using Terraform and Ansible.

Read in: ja
Building a Kubernetes Environment with Terraform and Ansible

Overview

I worked on building a Kubernetes environment using Terraform and Ansible.

I started building the environment from the desire to run my own application on Kubernetes.

Server Selection

Since this is for private development, I want to keep the budget around 2000 yen per month.

The major considerations are whether to use cloud or VPS, managed or unmanaged services, but I think I won't have too much trouble deciding that while considering cost and operational benefits. As mentioned later, the biggest headache was the load balancer...

Three options came up this time.

GCP

Digital Ocean

Conoha VPS

In addition to the above, I considered the option of managed k3s provided by civo.com, but since I wanted to work with k8s, I decided against it.

I was torn between Digital Ocean and Conoha, but I was captivated by the reassuring pricing structure with no usage charges, so I chose Conoha.

I believe GKE and Digital Ocean provide a suitable environment for quickly setting up Kubernetes for study purposes, so I made the decision to consider using them for that purpose.

Building a Kubernetes Environment on Conoha VPS

Since I chose not to use managed Kubernetes, I decided to build Kubernetes myself.

I adopted kubeadm as the tool for the setup.

Using Terraform and Ansible, I coded everything from instance creation to initial setup (user creation, SSH key adjustments, etc.) and the construction of Kubernetes using kubeadm, which can be found here:

github.com - bmf-san/setup-kubernetes-cluster-on-vps-boilerplate

It is designed for one master node and multiple worker nodes.

Conoha provides an API that supports OpenStack, so it should be easy to modify for other servers that support OpenStack (e.g., Digital Ocean).

Building Kubernetes with kubeadm was not too difficult as long as I read the official Kubernetes documentation to understand the prerequisites.

Issues That Could Not Be Resolved

I couldn't address the load balancer issue, so I was unable to publish the application and operate it on Kubernetes.

In the case of a self-hosted Kubernetes cluster, I cannot use the load balancer provided by the cloud, so I need to prepare an open-source solution myself, but I was unable to successfully set that up and had to give up...

I spent nearly a week sacrificing sleep but couldn't make any progress... lol

The unresolved issue is this one. https://github.com/kubernetes/ingress-nginx/issues/5401

I decided to temporarily switch to running my application with docker-compose and plan to deepen my understanding of Kubernetes operations before trying again...

Tags: Ansible Kubernetes Terraform kubeadm
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles