From 84260b5e3c528322267b3b79b9b00dd5c64b46f9 Mon Sep 17 00:00:00 2001 From: jem Date: Fri, 28 Jan 2022 16:44:59 +0100 Subject: [PATCH] apple tut --- .../provs/server/domain/k3s/K3sService.kt | 11 +++-- .../provs/server/infrastructure/K3s.kt | 25 +++++++---- .../provs/infrastructure/k3s/apple.yaml | 42 +++++++++++++++++++ .../k3s/config.yaml.template.dual | 4 +- .../k3s/config.yaml.template.ipv4 | 5 ++- 5 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/apple.yaml diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt index f29b62b..468fda9 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/domain/k3s/K3sService.kt @@ -14,7 +14,12 @@ import org.domaindrivenarchitecture.provs.server.infrastructure.provisionNetwork * If tlsHost is specified, then tls (if configured) also applies to the specified host. */ fun Prov.provisionK3s() = task { - provisionNetwork(loopbackIpv4 = "192.168.5.1", loopbackIpv6 = "fc00::5:1") - provisionK3sInfra(tlsName = "statistics.prod.meissa-gmbh.de", nodeIpv4 = "162.55.166.39", nodeIpv6 = "2a01:4f8:c010:622b::1", - loopbackIpv4 = "192.168.5.1", loopbackIpv6 = "fc00::5:1") + val loopbackIpv4 = "192.168.5.1" + val loopbackIpv6 = "fc00::5:1" + val nodeIpv4 = "162.55.164.138" + val nodeIpv6 = "2a01:4f8:c010:622b::1" + + provisionNetwork(loopbackIpv4 = loopbackIpv4, loopbackIpv6 = loopbackIpv6) + provisionK3sInfra(tlsName = "statistics.prod.meissa-gmbh.de", nodeIpv4 = nodeIpv4, nodeIpv6 = nodeIpv6, + loopbackIpv4 = loopbackIpv4, loopbackIpv6 = loopbackIpv6, installApple = true) } diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt index a1dd975..367d625 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/K3s.kt @@ -4,11 +4,11 @@ import org.domaindrivenarchitecture.provs.framework.core.Prov import org.domaindrivenarchitecture.provs.framework.core.ProvResult import org.domaindrivenarchitecture.provs.framework.ubuntu.filesystem.base.* -// TODO: jem - 2022.01.24 - these are global vars without scope / ns ! -val k3sConfigFile = "/etc/rancher/k3s/config.yaml" -val k3sCalicoFile = "/var/lib/rancher/k3s/server/manifests/calico.yaml" -val k3sInstallFile = "/usr/local/bin/k3s-install.sh" -val k3sResourcePath = "org/domaindrivenarchitecture/provs/infrastructure/k3s/" +private const val k3sConfigFile = "/etc/rancher/k3s/config.yaml" +private const val k3sCalicoFile = "/var/lib/rancher/k3s/server/manifests/calico.yaml" +private const val k3sAppleFile = "/var/lib/rancher/k3s/server/manifests/apple.yaml" +private const val k3sInstallFile = "/usr/local/bin/k3s-install.sh" +private const val k3sResourcePath = "org/domaindrivenarchitecture/provs/infrastructure/k3s/" fun Prov.testConfigExists(): Boolean { return fileExists(k3sConfigFile) @@ -26,7 +26,8 @@ fun Prov.deprovisionK3sInfra() = task { * If tlsHost is specified, then tls (if configured) also applies to the specified host. */ fun Prov.provisionK3sInfra(tlsName: String, nodeIpv4: String, loopbackIpv4: String, loopbackIpv6: String, - nodeIpv6: String? = null, docker: Boolean = false, tlsHost: String? = null) = task { + nodeIpv6: String? = null, docker: Boolean = false, installApple: Boolean = false, + tlsHost: String? = null) = task { val isDualStack = nodeIpv6?.isNotEmpty() ?: false if (testConfigExists()) { deprovisionK3sInfra() @@ -47,7 +48,6 @@ fun Prov.provisionK3sInfra(tlsName: String, nodeIpv4: String, loopbackIpv4: Stri "644", sudo = true ) - */ } else { k3sConfigFileName += ".ipv4" @@ -67,8 +67,15 @@ fun Prov.provisionK3sInfra(tlsName: String, nodeIpv4: String, loopbackIpv4: Stri "755", sudo = true ) - // TODO: doeas not work yet cmd("k3s-install.sh") - + // TODO: does not work yet cmd("k3s-install.sh") + cmd("sh /root/k3s-install.sh") + createFileFromResource( + k3sAppleFile, + "apple.yaml", + k3sResourcePath, + "644", + sudo = true + ) /* org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.template diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/apple.yaml b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/apple.yaml new file mode 100644 index 0000000..68af8e1 --- /dev/null +++ b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/apple.yaml @@ -0,0 +1,42 @@ +kind: Ingress +apiVersion: networking.k8s.io/v1 +metadata: + name: apple-ingress + annotations: + kubernetes.io/ingress.class: "traefik" +spec: + rules: + - http: + paths: + - path: /apple + pathType: Prefix + backend: + service: + name: apple-service + port: + number: 5678 +--- + +kind: Pod +apiVersion: v1 +metadata: + name: apple-app + labels: + app: apple +spec: + containers: + - name: apple-app + image: hashicorp/http-echo + args: + - "-text=apple" +--- + +kind: Service +apiVersion: v1 +metadata: + name: apple-service +spec: + selector: + app: apple + ports: + - port: 5678 # Default port for image \ No newline at end of file diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.dual b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.dual index 39af559..bd8073d 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.dual +++ b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.dual @@ -1,4 +1,3 @@ -etcd-disable-snapshots: true default-local-storage-path: /var tls-san: ${tls_name} disable-network-policy: true @@ -11,4 +10,5 @@ service-cidr: node-ip: - ${node_ipv4} - ${node_ipv6} -bind-address: ${loopback_ipv4} \ No newline at end of file +bind-address: ${loopback_ipv4} +advertise-address: ${loopback_ipv4} \ No newline at end of file diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.ipv4 b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.ipv4 index c6141e8..434ef6d 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.ipv4 +++ b/src/main/resources/org/domaindrivenarchitecture/provs/infrastructure/k3s/config.yaml.template.ipv4 @@ -1,10 +1,11 @@ -etcd-disable-snapshots: true default-local-storage-path: /var tls-san: ${tls_name} +disable-network-policy: true cluster-cidr: - 10.42.0.0/16 service-cidr: - 10.43.0.0/16 node-ip: - ${node_ipv4} -bind-address: ${loopback_ipv4} \ No newline at end of file +bind-address: ${loopback_ipv4} +advertise-address: ${loopback_ipv4} \ No newline at end of file