diff --git a/charts/apps/ingress/Chart.yaml b/charts/apps/ingress/Chart.yaml new file mode 100644 index 0000000..b370869 --- /dev/null +++ b/charts/apps/ingress/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: ingress +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/charts/apps/ingress/templates/dummy-pod.yaml b/charts/apps/ingress/templates/dummy-pod.yaml new file mode 100644 index 0000000..9454f4c --- /dev/null +++ b/charts/apps/ingress/templates/dummy-pod.yaml @@ -0,0 +1,38 @@ +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: dummy-app + namespace: "{{ .Release.Namespace }}" +spec: + replicas: 1 + selector: + matchLabels: + app: dummy + template: + metadata: + labels: + app: dummy + spec: + containers: + - name: name + image: nginxdemos/hello + resources: + limits: + memory: 1Gi + ports: + - containerPort: 80 +--- +kind: Service +apiVersion: v1 +metadata: + name: dummy-app +spec: + selector: + app: dummy + release: "{{ .Release.Name }}" + type: ClusterIP + ports: + - name: http + port: 80 + targetPort: 80 \ No newline at end of file diff --git a/k8s/argocd/.gitkeep b/charts/apps/ingress/values.yaml similarity index 100% rename from k8s/argocd/.gitkeep rename to charts/apps/ingress/values.yaml diff --git a/charts/infrastructure/Chart.yaml b/charts/infrastructure/Chart.yaml index 5e14aea..db5fe4c 100644 --- a/charts/infrastructure/Chart.yaml +++ b/charts/infrastructure/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: cluster description: An infrastructure collection of manifests for homelab type: application -version: 0.1.2 +version: 0.1.4 diff --git a/charts/infrastructure/templates/argo-repo.yaml b/charts/infrastructure/templates/argo-repo.yaml new file mode 100644 index 0000000..eb5807b --- /dev/null +++ b/charts/infrastructure/templates/argo-repo.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: argo-repo-main + namespace: "{{ .Values.ns.argocd }}" + labels: + argocd.argoproj.io/secret-type: repository + annotations: + link.argocd.argoproj.io/external-link: "https://github.com/{{ .Values.gitops.repo }}" +stringData: + type: git + url: "git@github.com:{{ .Values.gitops.repo }}.git" + sshPrivateKey: {{ .Values.gitops.sshkey | quote }} diff --git a/charts/infrastructure/templates/ips.yml b/charts/infrastructure/templates/ips.yml index d500934..6a3a87b 100644 --- a/charts/infrastructure/templates/ips.yml +++ b/charts/infrastructure/templates/ips.yml @@ -5,8 +5,7 @@ metadata: name: homelab-pool namespace: "{{ .Values.ns.metallb }}" spec: - addresses: - - 10.0.100.1-10.0.100.255 + addresses: {{ .Values.metallb.addresses }} --- apiVersion: metallb.io/v1beta1 kind: L2Advertisement diff --git a/charts/infrastructure/values.yaml b/charts/infrastructure/values.yaml index faf814f..3c5a9b6 100644 --- a/charts/infrastructure/values.yaml +++ b/charts/infrastructure/values.yaml @@ -1,3 +1,22 @@ +global: + timezone: America/Toronto + nfs: + server: 10.0.10.1 + rootPath: /mnt/EightTerra/k3s-cluster/direct-mounts + registry: ip: 10.0.100.101 - image: registry:2 \ No newline at end of file + image: registry:2 + +ns: + metallb: "change-me" + argocd: "change-me" + +gitops: + commit: "v2" + repo: "asosnovsky/homelab" + sshkey: "" + +metallb: + addresses: + - 10.0.100.1-10.0.100.255 \ No newline at end of file diff --git a/k8s/argoapps/Chart.yaml b/k8s/argoapps/Chart.yaml deleted file mode 100644 index 58d62a7..0000000 --- a/k8s/argoapps/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v2 -name: argoapps -description: An k8s service for homelab -type: application -version: 0.1.0 -dependencies: [] diff --git a/k8s/argoapps/templates/_helpers/application.yaml b/k8s/argoapps/templates/_helpers/application.yaml deleted file mode 100644 index d206d6c..0000000 --- a/k8s/argoapps/templates/_helpers/application.yaml +++ /dev/null @@ -1,29 +0,0 @@ -{{ define "homelab.argo.applicaton" }} ---- -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: "{{ .name }}" -spec: - project: {{ .project }} - source: - repoURL: "git@github.com:{{ .Values.gitops.repo }}.git" - targetRevision: "{{ .Values.gitops.commit }}" - path: '{{ .rootFolder }}/{{ .name }}' - helm: - valueFiles: - - values.yaml - - values-{{.Values.global.deployment}}.yaml - values: |- - global: - {{- .Values.global | toYaml | nindent 12 }} - releaseName: {{ .name }} - destination: - server: https://kubernetes.default.svc - namespace: {{ .namespace }} - {{- if .syncPolicy }} - syncPolicy: - {{- .syncPolicy | toYaml | nindent 4 }} - {{ end }} - -{{ end }} \ No newline at end of file diff --git a/k8s/argoapps/templates/_helpers/project.yaml b/k8s/argoapps/templates/_helpers/project.yaml deleted file mode 100644 index 5b3b21b..0000000 --- a/k8s/argoapps/templates/_helpers/project.yaml +++ /dev/null @@ -1,22 +0,0 @@ -{{ define "homelab.argo.project" }} ---- -apiVersion: argoproj.io/v1alpha1 -kind: AppProject -metadata: - name: {{ .name }} - finalizers: - - resources-finalizer.argocd.argoproj.io -spec: - description: {{ .description }} - orphanedResources: - warn: false - sourceRepos: - - "*" - destinations: - - server: "*" - namespace: '*' - name: '*' - clusterResourceWhitelist: - - group: "*" - kind: "*" -{{ end }} \ No newline at end of file diff --git a/k8s/argoapps/templates/argoappset-apps.yaml b/k8s/argoapps/templates/argoappset-apps.yaml deleted file mode 100644 index 71075fb..0000000 --- a/k8s/argoapps/templates/argoappset-apps.yaml +++ /dev/null @@ -1,54 +0,0 @@ -{{- $argoappsetApps := "apps" -}} -{{ include "homelab.argo.project" (dict "name" $argoappsetApps "description" "common applications")}} - - -{{ range $appName, $appProps := .Values.apps }} - -{{ if (not $appProps.disabled) }} - -{{- $genNamespace := (printf "apps-%s" $appName) -}} - -{{ if (not $appProps.namespace) }} ---- -apiVersion: v1 -kind: Namespace -metadata: - name: "{{ $genNamespace }}" -{{ end }} - ---- -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: app-{{ $appName }} -spec: - project: {{ $argoappsetApps }} - source: - repoURL: "git@github.com:{{ $.Values.gitops.repo }}.git" - targetRevision: "{{ $.Values.gitops.commit }}" - path: 'k8s/apps/{{ $appName }}' - helm: - valueFiles: - - values.yaml - - values-{{$.Values.global.deployment}}.yaml - values: |- -{{- $values := ($appProps.values| default "") -}} -{{ if $appProps.valuesFile }} -{{- $valuesFilePath := (printf "apps-values/%s" $appProps.valuesFile) -}} -{{- $values := $.Files.Get $valuesFilePath -}} - {{- tpl $values $ | nindent 10 -}} -{{- else -}} - {{- tpl $values $ | nindent 10 -}} -{{- end }} - global: - {{- $.Values.global | toYaml | nindent 12 }} - releaseName: {{ $appName }} - destination: - server: https://kubernetes.default.svc - namespace: {{ $appProps.namespace | default $genNamespace }} - {{ if $appProps.syncPolicy }} - syncPolicy: - {{$appProps.syncPolicy | toYaml | nindent 4 }} - {{ end }} -{{ end }} -{{ end }} diff --git a/k8s/argoapps/templates/argoappset-infrastructure.yaml b/k8s/argoapps/templates/argoappset-infrastructure.yaml deleted file mode 100644 index 1f53a56..0000000 --- a/k8s/argoapps/templates/argoappset-infrastructure.yaml +++ /dev/null @@ -1,26 +0,0 @@ -{{- $argoappsetInfra := "infrastructure" -}} - -{{- include "homelab.argo.project" (dict "name" $argoappsetInfra "description" "Infrastructure related charts") -}} - - -{{- range $appName, $appProps := .Values.infrastructure -}} - {{- $_ := set $appProps "Values" $.Values -}} - {{- $_ := set $appProps "name" (default $appProps.name $appName) -}} - {{- $_ := set $appProps "project" (default $appProps.project $argoappsetInfra) -}} - {{- $_ := set $appProps "namespace" (default $appProps.namespace $appName) -}} - {{- $_ := set $appProps "rootFolder" "k8s/infrastructure" -}} - - {{- if (not $appProps.disabled) -}} - {{- if $appProps.createNamespace -}} ---- -apiVersion: v1 -kind: Namespace -metadata: - name: "{{ $appProps.namespace }}" - {{ end }} - - {{- include "homelab.argo.applicaton" $appProps -}} - - {{- end -}} - -{{- end -}} diff --git a/k8s/argoapps/templates/charts-infra.yaml b/k8s/argoapps/templates/charts-infra.yaml deleted file mode 100644 index 84ca0fe..0000000 --- a/k8s/argoapps/templates/charts-infra.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -{{- $infraChartProjectName := "infrastructure-charts" -}} -{{ include "homelab.argo.project" (dict "name" $infraChartProjectName "description" "infrastructure helm charts")}} - -{{ range $chartName, $chartProps := .Values.infrastructureCharts }} - -{{- $namespace := $chartProps.namespace | default (printf "chart-%s" $chartName) -}} - -{{ if (not $chartProps.namespace) }} ---- -apiVersion: v1 -kind: Namespace -metadata: - name: "{{ $namespace }}" -{{ end }} - ---- -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: chart-{{ $chartName }} -spec: - project: {{ $infraChartProjectName }} - source: - chart: {{ $chartProps.chart | default $chartName }} - repoURL: {{ $chartProps.repoURL }} - targetRevision: {{ $chartProps.targetRevision }} - helm: - values: |- -{{- $values := ($chartProps.values | default "") -}} -{{ if $chartProps.valuesFile }} -{{- $valuesFilePath := (printf "chart-values/%s" $chartProps.valuesFile) -}} -{{- $values := $.Files.Get $valuesFilePath -}} - {{- tpl $values $ | nindent 8 }} -{{ else }} - {{- tpl $values $ | nindent 8 }} -{{ end }} - releaseName: {{ $chartName }} - destination: - server: https://kubernetes.default.svc - namespace: {{ $namespace }} - syncPolicy: - automated: - selfHeal: true - {{ if $chartProps.enableServerSideApply}} - syncOptions: - - ServerSideApply=true - {{ end }} -{{ end }} \ No newline at end of file diff --git a/k8s/argoapps/templates/cluster-limits.yaml b/k8s/argoapps/templates/cluster-limits.yaml deleted file mode 100644 index 6021efc..0000000 --- a/k8s/argoapps/templates/cluster-limits.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -apiVersion: v1 -kind: LimitRange -metadata: - name: cpu-limit-range -spec: - limits: - - defaultRequest: - cpu: 10m - type: Container ---- -apiVersion: v1 -kind: LimitRange -metadata: - name: mem-limit-range -spec: - limits: - - default: - memory: 50Mi - defaultRequest: - memory: 25Mi - type: Container \ No newline at end of file diff --git a/k8s/argoapps/values-dev.yaml b/k8s/argoapps/values-dev.yaml deleted file mode 100644 index 40c50e8..0000000 --- a/k8s/argoapps/values-dev.yaml +++ /dev/null @@ -1,2 +0,0 @@ -global: - deployment: dev diff --git a/k8s/argoapps/values-prod.yaml b/k8s/argoapps/values-prod.yaml deleted file mode 100644 index 2df1d21..0000000 --- a/k8s/argoapps/values-prod.yaml +++ /dev/null @@ -1,2 +0,0 @@ -global: - deployment: prod \ No newline at end of file diff --git a/k8s/argoapps/values.yaml b/k8s/argoapps/values.yaml deleted file mode 100644 index 5537d1b..0000000 --- a/k8s/argoapps/values.yaml +++ /dev/null @@ -1,15 +0,0 @@ -gitops: - repo: "" - commit: "" - -global: - email: "ariel@sosnovsky.ca" - timezone: America/Toronto - - -infrastructureCharts: {} -apps: {} -infrastructure: - metallb: - createNamespace: true - namespace: metallb-system \ No newline at end of file diff --git a/k8s/argocd/.helmignore b/k8s/argocd/.helmignore deleted file mode 100644 index 0e8a0eb..0000000 --- a/k8s/argocd/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/k8s/argocd/Chart.yaml b/k8s/argocd/Chart.yaml deleted file mode 100644 index f27116f..0000000 --- a/k8s/argocd/Chart.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v2 -name: argocd -description: Homelab Infra -type: application -version: 0.1.0 -dependencies: - - name: argo-cd - version: 7.6.12 - repository: https://argoproj.github.io/argo-helm diff --git a/k8s/argocd/templates/app-self.yaml b/k8s/argocd/templates/app-self.yaml deleted file mode 100644 index fef352c..0000000 --- a/k8s/argocd/templates/app-self.yaml +++ /dev/null @@ -1,91 +0,0 @@ ---- -apiVersion: v1 -kind: Secret -metadata: - name: argo-repo-main - namespace: "{{ .Release.Namespace }}" - labels: - argocd.argoproj.io/secret-type: repository - annotations: - link.argocd.argoproj.io/external-link: "https://github.com/{{ .Values.gitops.repo }}" -stringData: - type: git - url: "git@github.com:{{ .Values.gitops.repo }}.git" - sshPrivateKey: {{ .Values.selfapp.sshkey | quote }} - - -{{ if .Values.selfapp.enabled }} ---- -apiVersion: argoproj.io/v1alpha1 -kind: AppProject -metadata: - name: argocd - finalizers: - - resources-finalizer.argocd.argoproj.io -spec: - description: common applications - orphanedResources: - warn: false - sourceRepos: - - "*" - destinations: - - server: "*" - namespace: '*' - name: '*' - clusterResourceWhitelist: - - group: "*" - kind: "*" ---- -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: "{{ .Release.Name }}" - namespace: "{{ .Release.Namespace }}" -spec: - project: argocd - source: - repoURL: "git@github.com:{{ .Values.gitops.repo }}.git" - targetRevision: "{{ .Values.gitops.commit }}" - path: k8s/argocd - helm: - valueFiles: - - values.yaml - - values-{{ .Values.selfapp.deployment }}.yaml - parameters: - - name: "selfapp.deployment" - value: {{ .Values.selfapp.deployment | quote }} - - name: "selfapp.enabled" - value: "true" - - name: "selfapp.sshkey" - value: {{ .Values.selfapp.sshkey | quote }} - destination: - server: https://kubernetes.default.svc - namespace: "{{ .Release.Namespace }}" - ---- -apiVersion: argoproj.io/v1alpha1 -kind: Application -metadata: - name: "argoapps" - namespace: "{{ .Release.Namespace }}" -spec: - project: argocd - source: - repoURL: "git@github.com:{{ .Values.gitops.repo }}.git" - targetRevision: "{{ .Values.gitops.commit }}" - path: k8s/argoapps - helm: - valueFiles: - - values.yaml - - values-{{ .Values.selfapp.deployment }}.yaml - parameters: - - name: "gitops.repo" - value: {{ .Values.gitops.repo | quote }} - - name: "gitops.commit" - value: {{ .Values.gitops.commit | quote }} - destination: - server: https://kubernetes.default.svc - namespace: "{{ .Release.Namespace }}" - syncPolicy: - automated: {} -{{- end -}} \ No newline at end of file diff --git a/k8s/argocd/values-dev.yaml b/k8s/argocd/values-dev.yaml deleted file mode 100644 index c6996f9..0000000 --- a/k8s/argocd/values-dev.yaml +++ /dev/null @@ -1,2 +0,0 @@ -global: - domain: argocd.home.internal diff --git a/k8s/argocd/values-prod.yaml b/k8s/argocd/values-prod.yaml deleted file mode 100644 index 46010d3..0000000 --- a/k8s/argocd/values-prod.yaml +++ /dev/null @@ -1,2 +0,0 @@ -global: - domain: argocd.core.home.sosnovsky.ca diff --git a/k8s/argocd/values.yaml b/k8s/argocd/values.yaml deleted file mode 100644 index 897d8a2..0000000 --- a/k8s/argocd/values.yaml +++ /dev/null @@ -1,25 +0,0 @@ -argo-cd: - configs: - cm: - exec.enabled: true - params: - server.insecure: true - server.basehref: / - server.rootpath: "" - redis.server: "argocd-redis.argocd.svc.cluster.local:6379" - repo.server: "argocd-repo-server.argocd.svc.cluster.local:8081" - server.dex.server: "http://argocd-dex-server.argocd.svc.cluster.local:5556" - crds: - install: true - keep: false - server: - ingress: - enabled: false - ingressGrpc: - enabled: false -selfapp: - deployment: "" - sshkey: "" -gitops: - commit: "v2" - repo: "asosnovsky/homelab" diff --git a/modules.tf b/modules.tf deleted file mode 100644 index dbf95d7..0000000 --- a/modules.tf +++ /dev/null @@ -1,28 +0,0 @@ - -resource "helm_release" "local-chart-infrastructure" { - name = "infrastructure" - chart = "charts/infrastructure" - namespace = "default" - set = [{ - name = "ns.metallb" - value = module.k8s-helm-charts.namespaces.plugins.metallb - }] - values = [file("./values.yaml")] - timeout = 120 - force_update = true -} - -module "k8s-helm-charts" { - source = "./tf-modules/k8s-helm-charts" -} - -output "ns" { - value = module.k8s-helm-charts.namespaces -} - - -resource "kubernetes_namespace" "test" { - metadata { - name = "test" - } -} diff --git a/dns.tf b/tf-dns.tf similarity index 100% rename from dns.tf rename to tf-dns.tf diff --git a/tf-modules.tf b/tf-modules.tf new file mode 100644 index 0000000..5696aa4 --- /dev/null +++ b/tf-modules.tf @@ -0,0 +1,96 @@ + +resource "helm_release" "local-chart-infrastructure" { + name = "infrastructure" + chart = "charts/infrastructure" + namespace = "default" + set = [ + { + name = "ns.metallb" + value = module.k8s-helm-charts.namespaces.plugins.metallb + }, + { + name = "ns.argocd" + value = module.k8s-helm-charts.namespaces.plugins.argo-cd + }, + { + name = "gitops.sshkey" + value = var.ssh_key + } + ] + timeout = 120 + force_update = true +} + +module "k8s-helm-charts" { + source = "./tf-modules/k8s-helm-charts" + plugins = { + "external-secrets" : { + repository = "https://charts.external-secrets.io" + version = "0.14.2" + }, + "metallb" : { + repository = "https://metallb.github.io/metallb" + version = "0.14.9" + }, + "cert-manager" : { + repository = "https://charts.jetstack.io" + version = "1.17.1" + values : [yamlencode({ + installCRDs : true + })] + }, + "argo-cd" : { + "repository" : "https://argoproj.github.io/argo-helm" + "version" : "7.8.7" + "values" : [ + yamlencode({ + configs = { + cm = { + "exec.enabled" : true + } + params = { + "server.insecure" = true + "server.basehref" = "/" + "server.rootpath" = "" + } + } + crds = { + install = true + keep = false + } + server = { + ingress = { + enabled = false + } + ingressGrpc = { + enabled = false + } + } + }) + ] + }, + "tailscale-operator" : { + repository = "https://pkgs.tailscale.com/helmcharts" + version = "1.82.0" + values : [ + yamlencode({ + oauth = { + clientId = var.tailscale.client_id + clientSecret = var.tailscale.client_secret + } + }) + ] + } + } +} + +output "ns" { + value = module.k8s-helm-charts.namespaces +} + + +resource "kubernetes_namespace" "test" { + metadata { + name = "test" + } +} diff --git a/tf-modules/k8s-helm-charts/charts.tf b/tf-modules/k8s-helm-charts/charts.tf index 55ebcc1..021e00c 100644 --- a/tf-modules/k8s-helm-charts/charts.tf +++ b/tf-modules/k8s-helm-charts/charts.tf @@ -7,6 +7,7 @@ resource "helm_release" "plugins" { atomic = true namespace = "plugin-${each.key}" create_namespace = true + values = each.value.values } resource "helm_release" "infra" { diff --git a/tf-modules/k8s-helm-charts/variables.tf b/tf-modules/k8s-helm-charts/variables.tf index c69d7d1..c624f25 100644 --- a/tf-modules/k8s-helm-charts/variables.tf +++ b/tf-modules/k8s-helm-charts/variables.tf @@ -4,16 +4,7 @@ variable "plugins" { version = string values = optional(list(string), []) })) - default = { - "external-secrets" : { - repository = "https://charts.external-secrets.io" - version = "0.14.2" - }, - "metallb" : { - repository = "https://metallb.github.io/metallb" - version = "0.14.9" - } - } + default = {} } diff --git a/provider.tf b/tf-provider.tf similarity index 100% rename from provider.tf rename to tf-provider.tf diff --git a/tf-svc.tf b/tf-svc.tf new file mode 100644 index 0000000..e93171e --- /dev/null +++ b/tf-svc.tf @@ -0,0 +1,26 @@ +resource "kubernetes_service_v1" "argocd-metallb" { + metadata { + name = "argo-cd-server" + namespace = module.k8s-helm-charts.namespaces.plugins.argo-cd + annotations = { + "metallb.universe.tf/loadBalancerIPs" : "10.0.100.2" + } + } + spec { + type = "LoadBalancer" + port { + port = 80 + target_port = 8080 + name = "http" + } + port { + port = 443 + target_port = 8080 + name = "https" + } + selector = { + "app.kubernetes.io/instance" : "argo-cd" + "app.kubernetes.io/name" : "argocd-server" + } + } +} diff --git a/variables.tf b/tf-variables.tf similarity index 64% rename from variables.tf rename to tf-variables.tf index 4095dde..faf0871 100644 --- a/variables.tf +++ b/tf-variables.tf @@ -1,4 +1,5 @@ variable "cloudflare" { + sensitive = true type = object({ api_token = string account_id = string @@ -16,3 +17,13 @@ variable "domain_mappings" { type = optional(string, "A"), }))) } +variable "ssh_key" { + sensitive = true +} +variable "tailscale" { + type = object({ + client_id = string, + client_secret = string, + }) + sensitive = true +} diff --git a/values.yaml b/values.yaml deleted file mode 100644 index ba8b0b4..0000000 --- a/values.yaml +++ /dev/null @@ -1,5 +0,0 @@ -global: - timezone: America/Toronto - nfs: - server: 10.0.10.1 - rootPath: /mnt/EightTerra/k3s-cluster/direct-mounts \ No newline at end of file