Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kind for local setup #6

Merged
merged 14 commits into from
Nov 24, 2021
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- [Multi-Cloud Kubernetes](#multi-cloud-kubernetes)
- [Table of Contents](#table-of-contents)
- [Workflows](#workflows)
- [Cluster Workflows](#cluster-workflows)
- [Workload Workflows](#workload-workflows)
- [Other Workflows](#other-workflows)
- [Author Information](#author-information)
- [License](#license)

Expand All @@ -20,6 +23,7 @@ The code in this repository is split out into a handful of distinct workflows, e
* `./clusters/eks` contains code for AWS EKS Clusters
* `./clusters/doks` contains code for Digital Ocean Kubernetes Clusters
* `./clusters/gke` contains code for Google Cloud GKE Clusters
* `./clusters/kind` contains code for Kubernetes in Docker (kind) Clusters via `Terraform Kind Provider`
ksatirli marked this conversation as resolved.
Show resolved Hide resolved

### Workload Workflows

Expand Down
13 changes: 13 additions & 0 deletions clusters/kind/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions clusters/kind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Workspace `kind`

> This directory contains [kind Provider](https://registry.terraform.io/providers/kyma-incubator/kind/latest) Resources.

## Requirements

* Terraform CLI `1.0.8` or newer
ksatirli marked this conversation as resolved.
Show resolved Hide resolved

## Downstream Consumption

The Kubernetes Cluster can be consumed via the [kind_cluster](https://kind.sigs.k8s.io/docs/user/quick-start/) data source:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this line is interesting, because a data source would be the right approach, but there currently is none for kind_cluster specifically (looking at https://github.com/kyma-incubator/terraform-provider-kind/tree/master/kind).

That being said, this and lines #13-18 might need an update to reflect the consumption through a normal resource (vs. a data source).

Does that make sense?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep you are right there is no data-source . Sorry for the confusion


```hcl
# see https://registry.terraform.io/providers/kyma-incubator/kind/latest/docs/resources/cluster#attributes-reference
data "kind_cluster" "cluster" {
name = "multi-cloud-k8s"
}
```

## Execution Mode

Upon terraform initialization, make sure to:

1. YOUR_ORGANIZATION_NAME > Workspaces >YOUR_WORKSPACE_NAME > Settings > General
1. Switch `Execution Mode`from `Remote` to `Local`
1. Save the settings
36 changes: 36 additions & 0 deletions clusters/kind/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# see https://registry.terraform.io/providers/kyma-incubator/kind/latest
resource "kind_cluster" "cluster" {
name = var.tfe_workspaces_prefix
kubeconfig_path = pathexpand(var.kind_cluster_config_path)
wait_for_ready = true
# see https://github.com/kubernetes-sigs/kind/releases
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
node_image = "kindest/node:${var.kind_kubernetes_version}"
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
# see https://github.com/kyma-incubator/terraform-provider-kind/blob/master/kind/structure_kind_config.go
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
kind_config {
kind = "Cluster"
api_version = "kind.x-k8s.io/v1alpha4"
node {
role = "control-plane"
kubeadm_config_patches = [
"kind: InitConfiguration\nnodeRegistration:\n kubeletExtraArgs:\n node-labels: \"ingress-ready=true\"\n"
]
extra_port_mappings {
container_port = 80
host_port = 80
}
extra_port_mappings {
container_port = 443
host_port = 443
}
}
node {
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
role = "worker"
}
node {
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
role = "worker"
}
node {
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
role = "worker"
}
}
}
35 changes: 35 additions & 0 deletions clusters/kind/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_config" {
description = "Kind Cluster Config."
value = kind_cluster.cluster.kubeconfig
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_client_certificate" {
description = "Kind Cluster Client Certificate."
value = kind_cluster.cluster.client_certificate
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_client_key" {
description = "Kind Cluster Client Key."
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
value = kind_cluster.cluster.client_key
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_ca_certificate" {
description = "Kind Cluster CA Certificate."
value = kind_cluster.cluster.cluster_ca_certificate
}

# see https://www.terraform.io/docs/language/values/outputs.html
output "cluster_endpoint" {
description = "Kind Cluseter Endpoint."
value = kind_cluster.cluster.endpoint
}

# this variable is used for testing purposes and has no bearing on the demo
# see https://www.terraform.io/docs/language/values/outputs.html
output "workspace_url" {
value = "https://app.terraform.io/app/kind-local-organization/workspaces/${var.tfe_workspaces_prefix}-kind"
MChorfa marked this conversation as resolved.
Show resolved Hide resolved
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
}
2 changes: 2 additions & 0 deletions clusters/kind/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# see https://registry.terraform.io/providers/kyma-incubator/kind/latest
provider "kind" {}
23 changes: 23 additions & 0 deletions clusters/kind/terraform.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
terraform {
# see https://www.terraform.io/docs/language/settings/backends/remote.html
backend "remote" {
hostname = "app.terraform.io"
organization = "a-demo-organization"

workspaces {
name = "multi-cloud-k8s-kind"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-provider-requirements
required_providers {
# see https://registry.terraform.io/providers/kyma-incubator/kind/0.0.9
kind = {
source = "kyma-incubator/kind"
version = "0.0.9"
}
}

# see https://www.terraform.io/docs/language/settings/index.html#specifying-a-required-terraform-version
required_version = "1.0.9"
}
10 changes: 10 additions & 0 deletions clusters/kind/terraform.tfvars.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
variable "kind_kubernetes_version" {
type = string
default = "v1.21.1"
}
ksatirli marked this conversation as resolved.
Show resolved Hide resolved

variable "kind_cluster_config_path" {
type = string
description = "The location where this cluster's kubeconfig will be saved to."
default = "~/.kube/config"
}
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions clusters/kind/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "tfe_workspaces_prefix" {
type = string
description = "Prefix for TFE Workspaces."
default = "multi-cloud-k8s"
}

# see https://github.com/kubernetes-sigs/kind/releases
# The default node image is a Kubernetes v1.21.1
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
variable "kind_kubernetes_version" {
type = string
ksatirli marked this conversation as resolved.
Show resolved Hide resolved
default = "v1.21.1"
}

variable "kind_cluster_config_path" {
type = string
description = "The location where this cluster's kubeconfig will be saved to."
default = "~/.kube/config"
}
3 changes: 2 additions & 1 deletion outputs/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ variable "tfe_workspaces" {
"aks",
"eks",
"doks",
"gke"
"gke",
"kind"
]
}

Expand Down
4 changes: 4 additions & 0 deletions workspaces/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ variable "tfe_workspaces" {
execution_mode = "remote"
working_directory = "/clusters/gke"
}, {
description = "Manages Kind Clusters."
execution_mode = "local"
working_directory = "/clusters/kind"
}, {
description = "Collects Terraform Cloud Workspace Outputs."
execution_mode = "remote"
working_directory = "/outputs"
Expand Down