Skip to content

Commit 190834d

Browse files
committed
🔨 Add option to create local registry
1 parent 61af39c commit 190834d

File tree

4 files changed

+64
-15
lines changed

4 files changed

+64
-15
lines changed

main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ resource "kind_cluster" "this" {
4343
# kube_proxy_mode = null
4444
# }
4545

46-
containerd_config_patches = var.containerd_config_patches
47-
# TODO: Example patch
48-
# containerd_config_patches = [
49-
# <<-TOML
50-
# [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"]
51-
# endpoint = ["http://kind-registry:5000"]
52-
# TOML
53-
# ]
46+
containerd_config_patches = concat(var.containerd_config_patches, var.enable_registry == false ? [] : [
47+
<<-TOML
48+
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${var.registry_port}"]
49+
endpoint = ["http://${var.cluster_name}-registry:5000"]
50+
TOML
51+
])
5452
}
5553
}

option-registry.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# TODO: add local/private registry for kind cluster
1+
resource "docker_container" "registry" {
2+
count = var.enable_registry ? 1 : 0
3+
4+
name = "${var.cluster_name}-registry"
5+
image = docker_image.registry[0].latest
6+
restart = "always"
7+
8+
ports {
9+
internal = 5000
10+
11+
ip = "127.0.0.1"
12+
external = var.registry_port
13+
}
14+
15+
networks_advanced {
16+
name = "kind"
17+
}
18+
}
19+
20+
resource "docker_image" "registry" {
21+
count = var.enable_registry ? 1 : 0
22+
23+
name = "registry:2"
24+
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ variable "enable_metrics_server" {
4646
default = false
4747
}
4848

49+
variable "enable_registry" {
50+
description = "Set to true to install image registry as docker container."
51+
type = bool
52+
default = false
53+
}
54+
55+
variable "registry_port" {
56+
description = "Port of registry container."
57+
type = number
58+
default = 5000
59+
}
60+
4961
variable "containerd_config_patches" {
5062
description = "Path config to existing default for containerd."
5163
type = list(string)

versions.tf

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ terraform {
66
}
77
kubectl = {
88
source = "gavinbunney/kubectl"
9-
version = "~> 1.11"
9+
version = "~> 1.14"
1010
}
1111
docker = {
1212
source = "kreuzwerker/docker"
13-
version = "~> 2.15"
13+
version = "~> 2.16"
1414
}
1515
kubernetes = {
1616
source = "hashicorp/kubernetes"
17-
version = "~> 2.4"
17+
version = "~> 2.10"
1818
}
19-
random = {
20-
source = "hashicorp/random"
21-
version = "~> 3.1"
19+
helm = {
20+
source = "hashicorp/helm"
21+
version = "2.5.1"
2222
}
2323
}
2424
}
@@ -31,6 +31,22 @@ provider "kubectl" {
3131
cluster_ca_certificate = kind_cluster.this.cluster_ca_certificate
3232
}
3333

34+
provider "kubernetes" {
35+
host = kind_cluster.this.endpoint
36+
client_certificate = kind_cluster.this.client_certificate
37+
client_key = kind_cluster.this.client_key
38+
cluster_ca_certificate = kind_cluster.this.cluster_ca_certificate
39+
}
40+
41+
provider "helm" {
42+
kubernetes {
43+
host = kind_cluster.this.endpoint
44+
client_certificate = kind_cluster.this.client_certificate
45+
client_key = kind_cluster.this.client_key
46+
cluster_ca_certificate = kind_cluster.this.cluster_ca_certificate
47+
}
48+
}
49+
3450
provider "docker" {
3551
host = "unix:///var/run/docker.sock"
3652
}

0 commit comments

Comments
 (0)