-
Notifications
You must be signed in to change notification settings - Fork 55
k8s-tiller module #9
Changes from all commits
1790e2d
e4e75ad
89832f3
e2a6d43
567b705
3b5710b
a506e60
1a44f00
1820bec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# K8S Tiller | ||
|
||
This folder shows an example of how to deploy Tiller (the server component of Helm) on your Kubernetes cluster following | ||
the best practices for securing access. | ||
|
||
This guide requires a Kubernetes instance. You can either use: | ||
|
||
- [minikube](https://kubernetes.io/docs/tasks/tools/install-minikube/) | ||
- [Kubernetes on Docker for Mac](https://docs.docker.com/docker-for-mac/kubernetes/) | ||
- EKS | ||
- GKE | ||
|
||
|
||
## How do you run this example? | ||
|
||
In addition to Terraform, this example depends on modules that use the | ||
[`kubergrunt`](https://github.com/gruntwork-io/kubergrunt) utility under the hood. | ||
|
||
To run this example, apply the Terraform templates: | ||
|
||
1. Install [Terraform](https://www.terraform.io/), minimum version: `0.9.7`. | ||
1. Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/). | ||
1. Install [helm client](https://docs.helm.sh/using_helm/#install-helm) | ||
1. Install [kubergrunt](https://github.com/gruntwork-io/kubergrunt) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, that's a lot of stuff to install. I think I've asked before, but does it make sense to embed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't looked into this yet for That said, based on what I know, I think it is safe to assume that everyone will have I think the |
||
1. Open `variables.tf`, set the environment variables specified at the top of the file, and fill in any other variables | ||
that don't have a default. | ||
1. Run `terraform init`. | ||
1. Run `terraform apply`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
output "resource_namespace_name" { | ||
description = "Name of the created resource namespace" | ||
value = "${module.resource_namespace.name}" | ||
} | ||
|
||
output "resource_namespace_rbac_access_all_role" { | ||
description = "The name of the RBAC role that grants admin level permissions on the resource namespace." | ||
value = "${module.resource_namespace.rbac_access_all_role}" | ||
} | ||
|
||
output "resource_namespace_rbac_access_read_only_role" { | ||
description = "The name of the RBAC role that grants read only permissions on the resource namespace." | ||
value = "${module.resource_namespace.rbac_access_read_only_role}" | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,18 @@ terraform { | |
required_version = "~> 0.9" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# SET MODULE DEPENDENCY RESOURCE | ||
# This works around a terraform limitation where we can not specify module dependencies natively. | ||
# See https://github.com/hashicorp/terraform/issues/1178 for more discussion. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rileykarson Ok I found this pattern that was posted in December on module dependencies and it appears to be working well. I think this can be used to now chain the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain what this is meant to be used for? That is, what are you depending on? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main issue with GKE is that the default permissions are not enough to create additional RBAC roles. So you have to first promote the user to a cluster admin, and then you can proceed to create these roles. So in terraform, we need to make sure we apply these rules after the cluster admin role binding is created. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifically, your identity needs to have a superset of the permissions of a role to create that role. See https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control#defining_permissions_in_a_role |
||
|
||
resource "null_resource" "dependency_getter" { | ||
provisioner "local-exec" { | ||
command = "echo ${length(var.dependencies)}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On Powershell yes. I have verified this. This does not exist on CMD though so not the most portable, but probably good enough based on prior conversations. |
||
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# CREATE THE NAMESPACE | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
@@ -22,6 +34,8 @@ resource "kubernetes_namespace" "namespace" { | |
labels = "${var.labels}" | ||
annotations = "${var.annotations}" | ||
} | ||
|
||
depends_on = ["null_resource.dependency_getter"] | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
@@ -34,7 +48,7 @@ resource "kubernetes_namespace" "namespace" { | |
resource "kubernetes_role" "rbac_role_access_all" { | ||
metadata { | ||
name = "${var.name}-access-all" | ||
namespace = "${var.name}" | ||
namespace = "${kubernetes_namespace.namespace.id}" | ||
labels = "${var.labels}" | ||
annotations = "${var.annotations}" | ||
} | ||
|
@@ -48,8 +62,10 @@ resource "kubernetes_role" "rbac_role_access_all" { | |
|
||
resource "kubernetes_role" "rbac_role_access_read_only" { | ||
metadata { | ||
name = "${var.name}-access-read-only" | ||
namespace = "${var.name}" | ||
name = "${var.name}-access-read-only" | ||
namespace = "${kubernetes_namespace.namespace.id}" | ||
labels = "${var.labels}" | ||
annotations = "${var.annotations}" | ||
} | ||
|
||
rule { | ||
|
@@ -58,3 +74,15 @@ resource "kubernetes_role" "rbac_role_access_read_only" { | |
verbs = ["get", "list", "watch"] | ||
} | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# SET MODULE CHILD DEPENDENCY RESOURCE | ||
# This works around a terraform limitation where we can not specify module dependencies natively. | ||
# See https://github.com/hashicorp/terraform/issues/1178 for more discussion. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# List resource(s) that will be constructed last within the module, so that we can create an output that can be used to | ||
# chain dependencies. | ||
resource "null_resource" "dependency_setter" { | ||
depends_on = ["kubernetes_role.rbac_role_access_read_only", "kubernetes_role.rbac_role_access_all"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ output "rbac_access_read_only_role" { | |
description = "The name of the RBAC role that grants read only permissions on the namespace." | ||
value = "${kubernetes_role.rbac_role_access_read_only.metadata.0.name}" | ||
} | ||
|
||
output "depended_on" { | ||
description = "This output can be used to depend on the resources in this module." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Example use case? |
||
value = "${null_resource.dependency_setter.id}" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to our modules?