From a7a7e7561d4b87283cebf2f97bbda75ee472e86e Mon Sep 17 00:00:00 2001 From: Spike Curtis Date: Mon, 6 Jun 2022 14:39:23 -0700 Subject: [PATCH] K8s template uses an authenticated environment (#2104) * feat: K8s template uses authenticated environment Signed-off-by: Spike Curtis * fmt Signed-off-by: Spike Curtis --- .../kubernetes-multi-service/README.md | 116 +++++++++--------- .../kubernetes-multi-service/main.tf | 61 ++------- 2 files changed, 68 insertions(+), 109 deletions(-) diff --git a/examples/templates/kubernetes-multi-service/README.md b/examples/templates/kubernetes-multi-service/README.md index 3dda56db85..7c70d661f7 100644 --- a/examples/templates/kubernetes-multi-service/README.md +++ b/examples/templates/kubernetes-multi-service/README.md @@ -4,75 +4,71 @@ description: Get started with Kubernetes development. tags: [cloud, kubernetes] --- -# Authentication +# Getting started -This template features two ways to authenticate to a Kubernetes cluster. +## RBAC -## kubeconfig (Coder host) +The Coder provisioner requires permission to administer pods to use this template. The template +creates workspaces in a single Kubernetes namespace, using the `workspaces_namespace` parameter set +while creating the template. + +Create a role as follows and bind it to the user or service account that runs the coder host. + +```yaml +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: coder +rules: +- apiGroups: [""] + resources: ["pods"] + verbs: ["*"] +``` + +## Authentication + +This template can authenticate using in-cluster authentication, or using a kubeconfig local to the +Coder host. For additional authentication options, consult the [Kubernetes provider +documentation](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs). + +### kubeconfig on Coder host If the Coder host has a local `~/.kube/config`, you can use this to authenticate with Coder. Make sure this is done with same user that's running the `coder` service. -## ServiceAccount +To use this authentication, set the parameter `use_kubeconfig` to true. -Create a ServiceAccount and role on your cluster to authenticate your template with Coder. +### In-cluster authentication -1. Run the following command on a device with Kubernetes context: +If the Coder host runs in a Pod on the same Kubernetes cluster as you are creating workspaces in, +you can use in-cluster authentication. - ```sh - CODER_NAMESPACE=default - kubectl apply -n $CODER_NAMESPACE -f - <