Terraform with Kubernetes on premise?

Hi,

I couldn’t find the the answer. I see a lot of cloud providers that you can connect with Terraform.

The question is… if you are running Kubernetes on local servers, can Terraform connect to it?

Hi @fters

There shouldn’t be any differences between connection to a remote Kubernetes cluster or a local cluster.

See how to specify the credentials for the Terraform Kubernetes provider:

Be aware that most implementations and tutorials for a local Kubernetes cluster are really a for a single master doing all the work.

If you want to deploy a Kubernetes cluster with multiple workers for local development see the following tutorial that explains how to do it with Vagrant, Ansible and VirtualBox.

1 Like

Hi,

Thank you that is very very very useful information. I’m happy

Hi @fters

I am adding tutorials about Terraform and Kubernetes, first one explains how to use ~/.kube/config contexts to configure Terraform or even rename the context if needed.

The example code publishes 3 replicas of a Docker image from the public registry and creates a NodePort (as it is needed for Kubernetes on top of VirtualBox using Vagrant).

Please let me know if you were able to solve the connectivity issue.

I believe that Terraform Kubernets provider fallbacks to localhost if it can not find the Kubernetes contexts, printing errors like this:

Failed to create deployment: Post "http://localhost/apis/apps/v1/namespaces/default/deployments":

I would prefer a hard fail.