Skip to content

Commit

Permalink
add cilium instead kube-proxy and some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
runalsh committed Jul 3, 2024
1 parent 40d1310 commit b1f8966
Show file tree
Hide file tree
Showing 15 changed files with 285 additions and 93 deletions.
7 changes: 7 additions & 0 deletions cilium-module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "cilium" {
source = "./cilium"

kind_local_domain=var.kind_local_domain

count = var.cilium ? 1 : 0
}
102 changes: 102 additions & 0 deletions cilium/cilium.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
locals {
cilium_cert_secret = "cilium-https-cert"
}

resource "helm_release" "cilium" {
# count = var.use_cilium ? 1 : 0
name = "cilium"
repository = "https://helm.cilium.io/"
chart = "cilium"
version = "1.15.6"
namespace = "cilium"
create_namespace = true

set {
name = "image.pullPolicy"
value = "IfNotPresent"
}

set {
name = "ipam.mode"
value = "kubernetes"
}

set {
name = "hubble.enabled"
value = "true"
}

set {
name = "hubble.ui.enabled"
value = "true"
}

set {
name = "hubble.relay.enabled"
value = "true"
}
# # Make sure `kind` has written the `kubeconfig` before we move forward
# # with installing helm.
}

# module "cilium_tls" {
# # count = var.use_cilium ? 1 : 0
# source = "./modules/tls-cert"
# namespace = helm_release.cilium[0].namespace
# dns_names = [
# "hubble.${var.base_domain}"
# ]
# # certs_path = var.certs_path
# }

resource "kubectl_manifest" "hubble_grpc_service" {
# count = var.use_cilium ? 1 : 0
yaml_body = <<YAML
apiVersion: v1
kind: Service
metadata:
name: hubble-ui-grpc
namespace: ${helm_release.cilium.namespace}
spec:
ports:
- name: grpc
port: 80
protocol: TCP
targetPort: 8090
selector:
k8s-app: hubble-ui
type: ClusterIP
YAML
}


resource "kubectl_manifest" "hubble_ingress" {
# count = var.use_cilium ? 1 : 0
yaml_body = <<YAML
apiVersion: projectcontour.io/v1
kind: HTTPProxy
metadata:
name: hubble-ui
namespace: ${helm_release.cilium.namespace}
spec:
virtualhost:
fqdn: hubble.${var.kind_local_domain}
routes:
- conditions:
- prefix: /api
enableWebsockets: true
services:
- name: hubble-ui-grpc
port: 80
protocol: h2c
timeoutPolicy:
response: 1h
- conditions:
- prefix: /
enableWebsockets: true
services:
- name: hubble-ui
port: 80
YAML
}
10 changes: 10 additions & 0 deletions cilium/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.6.0"

required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
}
}
4 changes: 4 additions & 0 deletions cilium/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "kind_local_domain" {
type = string
default = "kind.local"
}
16 changes: 0 additions & 16 deletions kind-config
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCVENDQWUyZ0F3SUJBZ0lJZDNGekFNZFVicW93RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TkRBM01ESXdPRFEwTURGYUZ3MHpOREEyTXpBd09EUTVNREZhTUJVeApFekFSQmdOVkJBTVRDbXQxWW1WeWJtVjBaWE13Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLCkFvSUJBUUNndjZqaStHaDJtR1BlenZUMjdRUEczNXdhUzhrTnpaelY3Q0ZRODdlek5ldUo2a3oxbFBiYzVoV1UKY1JwUHZNSGZFZ296ZnkrWk90TDFzWmJOUythVlV2dG1CZ04rZHJZcW4vaUxUaEFHU2xwNkxiYmViRFRvZm1XaApaWm5hTWRENDdFbjl6VE5aUWFnR2QzSWZ1MGxkYUtHZncrTk5mVmJUZk96ZDRNUkFJeWNLb3NHS0IxTThrTmZxCmMrZHUrRmVhUG9zK0VJR2I0K0ZDckhtSFZzZ09OL2ZxN29sYzJCRTV0bnhpMmhEV0xPcDdEZzlqZ3RjeGxEUmwKcUtKREtGSlpzd1VmMkp0K1VlMGtIRjkrSTRoZ2UxS1hYMy9pQVhhT2VKU3ovUm95QTlxL1ZrRXBQaHIwQXhCYwozNlVCZXFoMlVqSkxjQVFBUXVXT3dWUG56a3d4QWdNQkFBR2pXVEJYTUE0R0ExVWREd0VCL3dRRUF3SUNwREFQCkJnTlZIUk1CQWY4RUJUQURBUUgvTUIwR0ExVWREZ1FXQkJUck0rVmViMXRzeEpTUVp4ZFI3aDV4K3F2aUJEQVYKQmdOVkhSRUVEakFNZ2dwcmRXSmxjbTVsZEdWek1BMEdDU3FHU0liM0RRRUJDd1VBQTRJQkFRQkN6QmZVUVpldApuQlB4YXo1NG5Id2dGc1kxbjIzNWdjOGd2d1RZSVJGcVN3dE42anpHa3M1WjFadW9ucXM5djlxRXlicThBOTVjCnJzTlVEcE05M0JDOFlmWUhVYzZXRnJEeGpzYkRqWnpuc3p3RnJsUmNqcWxYNWdYRmtMNEN3VlQxVThSQzBmWUIKR3hpUTdjcUt1WXZ5WGdjaythclJ4TDVCaE9hUmk1SUwremhWcGo5ajFybUpoYXJKTXU1eDFuaHhQcU1KY0UrMgpBN3JQOFBMZUVCVzh0UFZHZWZmV3dYYlNtRmo3UXU0V1F4K3ZNK3lxd01CZWZSc3NJTXdkNzB2N3FvVjR6dms3CmtRRUlmc2xmcExCcFNwdTVYaUtxVktDRTl4KzRUVGt0ZG9KcjBkWVljL1B5TDRxUVpTNVlhZEY4aEdYd0xLQXEKYVJ2M0VqK0RjS00vCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
server: https://127.0.0.1:59971
name: kind-kind
contexts:
- context:
cluster: kind-kind
user: kind-kind
name: kind-kind
current-context: kind-kind
kind: Config
preferences: {}
users:
- name: kind-kind
user:
client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURLVENDQWhHZ0F3SUJBZ0lJV1FXTzlQdXZpMzh3RFFZSktvWklodmNOQV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0FsQWYya3pyc3Zrb3dLQmdCRmpCNkJHVEszU1BNL29aRnVnK3pQa1BnQXlCRHhKWlhJbXVNc0EKNTRSbDQ2WVAyODlrOHU1L0crTUFlYit0N3BkN0lmTWR0TkdUTmdxd3RBSlUyRDBjaU9JVHY0cWhJaU5yaXVZQwpEejNFWlJHU1pCbnZMQlF4S3RkV1JnblBBUnNtaWZyQmdrS2JBb3hsbmJNVHB5UkpERi82cElUdVVsbVNKZ3VzCitDcXBBb0dBSW9tTWYxTE5rZ0Q4TXFRWmlKbVFOamM1TjFHNGExZXhHNE92bWhSMWcxankyV0dDWmJFMmVCSDEKZStBdCtFQ09YV2pnWXhvSGpOOS9yMnJrOFZ2UkNObVZnQldLcVVWWGpxV01KRzhHRGxqUnp4VUhKVHBneGJ1WgpYVXRkN0lBVVNHRzNSL3hzTWxLL1puVFBONys2c2dlTXJzRldoMjdVT3hFbjQxTlEvSE09Ci0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
8 changes: 8 additions & 0 deletions kind-module.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "kind" {
source = "./kind"

name = var.kind_cluster_name
kind_local_domain = var.kind_local_domain

count = var.kind ? 1 : 0
}
135 changes: 61 additions & 74 deletions kind(NO).tf → kind/kind.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
provider "kind" {
}

resource "kind_cluster" "kind" {
name = "kind"
name = var.name
wait_for_ready = true
# kubeconfig_path = pathexpand(locals.kubectl_config_path)
kind_config {
Expand All @@ -14,6 +12,11 @@ resource "kind_cluster" "kind" {
# config_path = "${local.containerd_config_path}"
# TOML
# ]
networking {
disable_default_cni = true
kube_proxy_mode = "none"
}

node {
role = "control-plane"
image = "kindest/node:v1.30.2"
Expand Down Expand Up @@ -48,33 +51,23 @@ resource "kind_cluster" "kind" {
}
}

# provider "helm" {
# kubernetes {
# config_path = var.kubectl_config_path == "" ? local.kubectl_config_path : var.kubectl_config_path
# config_context = "kind-${kind_cluster.kind.name}"
# }
# data "http" "kind_ingress_http" {
# url = "https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml"
# }
# data "kubectl_file_documents" "ingress_yaml_files" {
# content = data.http.kind_ingress_http.response_body
# }
# resource "kubectl_manifest" "ingress_manifest" {
# for_each = data.kubectl_file_documents.ingress_yaml_files.manifests
# yaml_body = each.value
# depends_on = [ kubernetes_namespace.ingress_namespace, kind_cluster.kind ]
# }
# resource "kubernetes_namespace" "ingress_namespace" {
# metadata {
# name = "ingress"
# }
# depends_on = [ kind_cluster.kind, data.kubectl_file_documents.ingress_yaml_files ]
# }

data "http" "kind_ingress_http" {
url = "https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml"
}
data "kubectl_file_documents" "nginx_yaml_files" {
content = data.http.kind_ingress_http.response_body
depends_on = [ kind_cluster.kind ]
}
resource "kubectl_manifest" "nginx_manifest" {
provider = kubectl
for_each = data.kubectl_file_documents.nginx_yaml_files.manifests
yaml_body = each.value
wait = true
depends_on = [ kubernetes_namespace.nginx_namespace, kind_cluster.kind ]
}
resource "kubernetes_namespace" "nginx_namespace" {
metadata {
name = "ingress-nginx"
}
depends_on = [ kind_cluster.kind, data.kubectl_file_documents.nginx_yaml_files ]
}

# #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Expand Down Expand Up @@ -113,7 +106,7 @@ resource "kubernetes_namespace" "nginx_namespace" {
# name = "configs.secret.argocdServerAdminPassword"
# value = bcrypt(var.argocd_admin_pass)
# }
# depends_on = [ kubectl_manifest.nginx_manifest ]
# depends_on = [ kubectl_manifest.ingress_manifest ]
# }

# // adding all the declartive argocd in the argo-apps folder to the cluster
Expand All @@ -125,56 +118,50 @@ resource "kubernetes_namespace" "nginx_namespace" {
# # depends_on = [ helm_release.helm_argo ]
# # }

# resource "helm_release" "metrics-server" {
# name = "metrics-server"
# chart = "metrics-server"
# namespace = "kube-system"
# repository = "https://kubernetes-sigs.github.io/metrics-server"

# set {
# name = "args"
# value = "{--kubelet-insecure-tls}"
# }
# depends_on = [ kind_cluster.kind ]
# }

# locals {
# cilium_cert_secret = "cilium-https-cert"
# }

# resource "helm_release" "cilium" {
# # count = var.use_cilium ? 1 : 0
# name = "cilium"
# repository = "https://helm.cilium.io/"
# chart = "cilium"
# version = "1.15.6"
# namespace = "cilium"
# create_namespace = true
#cilium install --version 1.15.6
#cilium hubble enable --ui
#cilium hubble ui

# # set {
# # name = "image.pullPolicy"
# # value = "IfNotPresent"
# # }

# # set {
# # name = "ipam.mode"
# # value = "kubernetes"
# # }

# # set {
# # name = "hubble.enabled"
# # value = "true"
# # }

# # set {
# # name = "hubble.ui.enabled"
# # value = "true"
# # }

# # set {
# # name = "hubble.relay.enabled"
# # value = "true"
# # }
# # # Make sure `kind` has written the `kubeconfig` before we move forward
# # # with installing helm.
# }
resource "helm_release" "cilium" {
name = "cilium"
repository = "https://helm.cilium.io/"
chart = "cilium"
version = "1.15.6"
# namespace = "cilium"
namespace = "kube-system"
wait = true
wait_for_jobs = true
create_namespace = true
timeout = 600
values = [file("${path.module}/../values/cilium.yaml")]
}

# module "cilium_tls" {
# # count = var.use_cilium ? 1 : 0
# source = "./modules/tls-cert"
# namespace = helm_release.cilium[0].namespace
# dns_names = [
# "hubble.${var.base_domain}"
# ]
# # certs_path = var.certs_path
# }
# # module "cilium_tls" {
# # # count = var.use_cilium ? 1 : 0
# # source = "./modules/tls-cert"
# # namespace = helm_release.cilium[0].namespace
# # dns_names = [
# # "hubble.${var.base_domain}"
# # ]
# # # certs_path = var.certs_path
# # }

# resource "kubectl_manifest" "hubble_grpc_service" {
# # count = var.use_cilium ? 1 : 0
Expand Down
3 changes: 3 additions & 0 deletions kind/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "kind_cluster_name" {
value = "kind-${kind_cluster.kind.name}"
}
18 changes: 18 additions & 0 deletions kind/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">= 1.6.0"

required_providers {
helm = {
source = "hashicorp/helm"
version = "2.13.2"
}
kubectl = {
source = "gavinbunney/kubectl"
version = "1.14.0"
}
kind = {
source = "tehcyx/kind"
version = "0.5.1"
}
}
}
21 changes: 21 additions & 0 deletions kind/vars.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
variable "kubectl_config_path" {
default = ""
type = string
}
data "external" "os" {
working_dir = path.module
program = ["printf", "{\"os\": \"Linux\"}"]
}
locals {
os = data.external.os.result.os
kubectl_config_path = local.os == "Windows" ? "%USERPROFILE%\\.kube\\config" : "~/.kube/config"
}

variable "name" {
type = string
}

variable "kind_local_domain" {
type = string
default = "kind.local"
}
4 changes: 3 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ provider "helm" {
kubernetes {
config_path = var.kubectl_config_path == "" ? local.kubectl_config_path : var.kubectl_config_path
# config_context = module.minikube.minikube_name
config_context = var.minikube_param.cluster_name
# config_context = var.minikube_param.cluster_name
# config_context = "kind-kind"
# config_context = "kind-${var.kind_cluster_name}"
config_context = var.minikube ? var.minikube_name : "kind-${var.kind_cluster_name}"
}
}

Expand Down
Loading

0 comments on commit b1f8966

Please sign in to comment.