From cf6d2cb88500a44705e66617fbd8e17535a3dfba Mon Sep 17 00:00:00 2001 From: jerger Date: Fri, 25 Nov 2022 21:23:58 +0100 Subject: [PATCH] add additional tunel to connect --- .../provs/desktop/infrastructure/DevOps.kt | 23 ------------- .../desktop/infrastructure/k3s-connect.sh | 5 ++- .../infrastructure/k3s-create-context.sh | 20 +++++++++++ .../desktop/infrastructure/k8s-connect.sh | 24 -------------- .../infrastructure/k8s-create-context.sh | 33 ------------------- 5 files changed, 24 insertions(+), 81 deletions(-) delete mode 100644 src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh delete mode 100644 src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt index e8b099f..556fb57 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure/DevOps.kt @@ -82,29 +82,6 @@ fun Prov.installDevopsScripts() { ) } - task("install k8sCreateContext") { - val k8sContextFile = "/usr/local/bin/k8s-create-context.sh" - createFileFromResource( - k8sContextFile, - "k8s-create-context.sh", - resourcePath, - "555", - sudo = true - ) - - } - - task("install k8sConnect") { - val k8sConnectFile = "/usr/local/bin/k8s-connect.sh" - createFileFromResource( - k8sConnectFile, - "k8s-connect.sh", - resourcePath, - "555", - sudo = true - ) - } - task("install k3sCreateContext") { val k3sContextFile = "/usr/local/bin/k3s-create-context.sh" createFileFromResource( diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh index bf462cc..b1ab76f 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-connect.sh @@ -12,7 +12,10 @@ function main() { /usr/local/bin/k3s-create-context.sh ${cluster_name} ${domain_name} kubectl config use-context ${cluster_name} - ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} \ + -L 8002:localhost:8002 \ + -L 6443:192.168.5.1:6443 \ + -L 9000:192.168.5.1:9000 } if [ $# -gt 0 ] diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh index e3206a5..9ffe809 100644 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh +++ b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k3s-create-context.sh @@ -6,6 +6,25 @@ function usage() { echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}" } +function sourceNewContext() { + DEFAULT_KUBE_CONTEXTS="$HOME/.kube/config" + if test -f "${DEFAULT_KUBE_CONTEXTS}" + then + export KUBECONFIG="$DEFAULT_KUBE_CONTEXTS" + fi + + # Additional contexts should be in ~/.kube/custom-contexts/ + CUSTOM_KUBE_CONTEXTS="$HOME/.kube/custom-contexts" + mkdir -p "${CUSTOM_KUBE_CONTEXTS}" + + OIFS="$IFS" + IFS=$'\n' + for contextFile in `find "${CUSTOM_KUBE_CONTEXTS}" -type f -name "*.yml"` + do + export KUBECONFIG="$contextFile:$KUBECONFIG" + done + IFS="$OIFS" +} function main() { local cluster_name="${1}"; @@ -22,6 +41,7 @@ function main() { | del(.preferences) \ | .users[0].name=\"${cluster_name}\"" - \ > ~/.kube/custom-contexts/${cluster_name}.yml + sourceNewContext } if [ $# -gt 0 ] diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh deleted file mode 100644 index cf9d2a3..0000000 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-connect.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -set -e -set -o noglob - -function usage() { - echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}" -} - -function main() { - local cluster_name="${1}"; shift - local domain_name="${1:-meissa-gmbh.de}"; shift - - /usr/local/bin/k8s-create-context.sh ${cluster_name} - kubectl config use-context ${cluster_name} - ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} -L 8002:localhost:8002 -L 6443:192.168.5.1:6443 -} - -if [ $# -gt 0 ] -then - main $1 -else - usage - exit -1 -fi diff --git a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh b/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh deleted file mode 100644 index 709d124..0000000 --- a/src/main/resources/org/domaindrivenarchitecture/provs/desktop/infrastructure/k8s-create-context.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -e -set -o noglob - -function usage() { - echo "Requires argument cluster_name and domain_name in server fqdn {cluster_name}.{domain_name}" -} - - -function main() { - local cluster_name="${1}"; shift - local domain_name="${1:-meissa-gmbh.de}"; shift - - ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@${cluster_name}.${domain_name} \ - "cat /etc/kubernetes/admin.conf" | \ - yq e ".clusters[0].name=\"${cluster_name}\" \ - | .clusters[0].cluster.server=\"https://kubernetes:6443\" \ - | .contexts[0].context.cluster=\"${cluster_name}\" \ - | .contexts[0].context.user=\"${cluster_name}\" \ - | .contexts[0].name=\"${cluster_name}\" \ - | del(.current-context) \ - | del(.preferences) \ - | .users[0].name=\"${cluster_name}\"" - \ - > ~/.kube/custom-contexts/${cluster_name}.yml -} - -if [ $# -gt 0 ] -then - main $1 -else - usage - exit -1 -fi