-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add local k8s cluster setup using Docker desktop.
- Loading branch information
1 parent
24d4eed
commit 87d8020
Showing
8 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 | | ||
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >=2.30 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.30.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [kubernetes_cluster_role_binding.example](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/cluster_role_binding) | resource | | ||
| [kubernetes_namespace.keyfactor_command](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | | ||
| [kubernetes_namespace.test](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | | ||
| [kubernetes_secret.admin_user_token](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret) | resource | | ||
| [kubernetes_service_account.admin_user](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service_account) | resource | | ||
| [kubernetes_namespace.dashboard](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_admin_user_token"></a> [admin\_user\_token](#output\_admin\_user\_token) | n/a | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.DEFAULT_GOAL := help | ||
|
||
##@ Utility | ||
help: ## Display this help | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
deps: ## Install deps for macos | ||
@brew install pre-commit tflint terraform terraform-docs | ||
|
||
docs: ## Run terraform-docs to update module docs. | ||
@terraform-docs markdown . > MODULE.MD | ||
@terraform-docs markdown table --output-file README.md --output-mode inject . | ||
|
||
lint: ## Run tflint | ||
@tflint | ||
|
||
validate: ## Run terraform validate | ||
@terraform init --upgrade | ||
@terraform validate | ||
|
||
precommit/add: ## Install pre-commit hook | ||
@pre-commit install | ||
|
||
precommit/remove: ## Uninstall pre-commit hook | ||
@pre-commit uninstall | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Docker Desktop Kubernetes Cluster | ||
This is a quick guide on how to setup a Kubernetes cluster using Docker Desktop that can be used for development purposes, | ||
and testing the Keyfactor Command Kubernetes Universal Orchestrator extension. | ||
|
||
## Prerequisites | ||
- [Docker Desktop](https://www.docker.com/products/docker-desktop) | ||
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) | ||
- [helm](https://helm.sh/docs/intro/install/) | ||
- [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli) | ||
|
||
## Kubernetes Setup | ||
1. Enable Kubernetes in Docker Desktop | ||
- Open Docker Desktop | ||
- Click on the Docker icon in the system tray | ||
- Click on `Settings` | ||
- Click on `Kubernetes` | ||
- Check the box for `Enable Kubernetes` | ||
- Click `Apply & Restart` | ||
2. Configure kubectl to use the Docker Desktop Kubernetes cluster | ||
- Run the following command in a terminal | ||
```shell | ||
kubectl config use-context docker-desktop | ||
``` | ||
3. Run the `setup_dashboard.sh` script to install the Kubernetes dashboard | ||
```shell | ||
./setup_dashboard.sh | ||
``` | ||
4. Run the terraform code to create the necessary resources | ||
```shell | ||
terraform init | ||
terraform apply | ||
``` | ||
Now the cluster is ready to be used for development and testing purposes. | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.5 | | ||
| <a name="requirement_kubernetes"></a> [kubernetes](#requirement\_kubernetes) | >=2.30 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_kubernetes"></a> [kubernetes](#provider\_kubernetes) | 2.30.0 | | ||
|
||
## Modules | ||
|
||
No modules. | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [kubernetes_cluster_role_binding.example](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/cluster_role_binding) | resource | | ||
| [kubernetes_namespace.keyfactor_command](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | | ||
| [kubernetes_namespace.test](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/namespace) | resource | | ||
| [kubernetes_secret.admin_user_token](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/secret) | resource | | ||
| [kubernetes_service_account.admin_user](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/resources/service_account) | resource | | ||
| [kubernetes_namespace.dashboard](https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs/data-sources/namespace) | data source | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_admin_user_token"></a> [admin\_user\_token](#output\_admin\_user\_token) | n/a | | ||
<!-- END_TF_DOCS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "kubernetes_namespace" "keyfactor_command" { | ||
metadata { | ||
name = "keyfactor-command" | ||
} | ||
} | ||
|
||
resource "kubernetes_namespace" "test" { | ||
metadata { | ||
name = "test" | ||
} | ||
} | ||
|
||
data "kubernetes_namespace" "dashboard" { | ||
metadata { | ||
name = "kubernetes-dashboard" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
terraform { | ||
required_version = ">= 1.5" | ||
required_providers { | ||
kubernetes = { | ||
source = "hashicorp/kubernetes" | ||
version = ">=2.30" | ||
} | ||
} | ||
} | ||
|
||
provider "kubernetes" { | ||
config_path = "~/.kube/config" | ||
config_context = "docker-desktop" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resource "kubernetes_cluster_role_binding" "example" { | ||
metadata { | ||
name = kubernetes_service_account.admin_user.metadata.0.name | ||
} | ||
role_ref { | ||
api_group = "rbac.authorization.k8s.io" | ||
kind = "ClusterRole" | ||
name = "cluster-admin" | ||
} | ||
subject { | ||
kind = "ServiceAccount" | ||
name = kubernetes_service_account.admin_user.metadata.0.name | ||
namespace = kubernetes_service_account.admin_user.metadata.0.namespace | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
resource "kubernetes_service_account" "admin_user" { | ||
metadata { | ||
name = "admin-user" | ||
namespace = data.kubernetes_namespace.dashboard.metadata.0.name | ||
} | ||
} | ||
|
||
resource "kubernetes_secret" "admin_user_token" { | ||
metadata { | ||
name = kubernetes_service_account.admin_user.metadata.0.name | ||
namespace = kubernetes_service_account.admin_user.metadata.0.namespace | ||
annotations = { | ||
"kubernetes.io/service-account.name" = kubernetes_service_account.admin_user.metadata.0.name | ||
} | ||
} | ||
|
||
type = "kubernetes.io/service-account-token" | ||
wait_for_service_account_token = true | ||
} | ||
|
||
output "admin_user_token" { | ||
value = kubernetes_secret.admin_user_token.data.token | ||
sensitive = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
kubectl config use-context docker-desktop | ||
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/ | ||
helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard | ||
kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443 |