v0.8.22-SNAPSHOT add k3s

This commit is contained in:
az 2021-11-25 11:09:26 +01:00
parent 2f308cbbb2
commit c31d115ea5
2 changed files with 56 additions and 1 deletions

View file

@ -18,7 +18,7 @@ apply plugin: 'kotlinx-serialization'
group = 'org.domaindrivenarchitecture.provs' group = 'org.domaindrivenarchitecture.provs'
version = '0.8.21' version = '0.8.22-SNAPSHOT'
repositories { repositories {
mavenCentral() mavenCentral()

View file

@ -0,0 +1,55 @@
package org.domaindrivenarchitecture.provs.extensions.server_software.k3s
import org.domaindrivenarchitecture.provs.core.Prov
import org.domaindrivenarchitecture.provs.core.ProvResult
import org.domaindrivenarchitecture.provs.core.remote
import org.domaindrivenarchitecture.provs.ubuntu.install.base.aptInstall
import org.domaindrivenarchitecture.provs.ubuntu.secret.secretSources.PromptSecretSource
/**
* Installs a k3s server.
* If docker is true, then k3s will be installed with docker option and also docker will be installed (may conflict if docker is already existing).
* If host is specified, then tls (if configured) also applies to host.
*/
fun Prov.installK3sServer(docker: Boolean = false, host: String? = null) = def {
val tls = host?.let { "INSTALL_K3S_EXEC=\"--tls-san ${it}\"" } ?: ""
aptInstall("curl")
if (!chk("k3s -version")) {
if (docker) {
// might not work if docker already installed
sh("""
curl https://releases.rancher.com/install-docker/19.03.sh | sh
curl -sfL https://get.k3s.io | sh -s - --docker
""".trimIndent())
} else {
cmd("curl -sfL https://get.k3s.io | $tls sh -")
}
} else {
ProvResult(true)
}
}
fun Prov.uninstallK3sServer() = def {
cmd("sudo /usr/local/bin/k3s-uninstall.sh")
}
fun main() {
val host = "192.168.56.123"
val remoteUser = "remoteUsername"
val passwordK3sUser = PromptSecretSource("Enter Password").secret()
remote(host, remoteUser, passwordK3sUser).def {
val result = installK3sServer()
// print pods for information purpose
println(cmd("sudo k3s kubectl get pods --all-namespaces").out)
// return result of installation
result
}
}