From f9ea9ab0599b8506c771f78c304f23434e2346e5 Mon Sep 17 00:00:00 2001 From: Helmut Hutzler <helmut.hutzler@th-nuernberg.de> Date: Thu, 5 Aug 2021 07:27:32 +0000 Subject: [PATCH] Kubernetes Setup Files for ODIC Autologin wiht Angular12 --- .../oidc-autologin-angular-12-staging.yaml | 81 +++++++++++++++++++ .../OIDC-AUTOLOGIN-Angular12/build-staging.sh | 75 +++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/YAML/oidc-autologin-angular-12-staging.yaml create mode 100755 GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/build-staging.sh diff --git a/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/YAML/oidc-autologin-angular-12-staging.yaml b/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/YAML/oidc-autologin-angular-12-staging.yaml new file mode 100644 index 0000000..1906df6 --- /dev/null +++ b/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/YAML/oidc-autologin-angular-12-staging.yaml @@ -0,0 +1,81 @@ +apiVersion: v1 +kind: Service +metadata: + annotations: + note: Hello, I am staging! + labels: + app: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + name: staging-oidc-autologin-angular-12-svc +spec: + ports: + - port: 9605_ + protocol: TCP + targetPort: 80 + selector: + app: oidc-autologin-angular-12-app + deployment: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + type: LoadBalancer +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + note: Hello, I am staging! + labels: + app: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + name: staging-oidc-autologin-angular-12-pod +spec: + replicas: 1 + selector: + matchLabels: + app: oidc-autologin-angular-12-app + deployment: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + template: + metadata: + annotations: + note: Hello, I am staging! + labels: + app: oidc-autologin-angular-12-app + deployment: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + spec: + containers: + - image: harbor.informatik.fh-nuernberg.de/hutzler/oidc-autologin-angular-12-staging + imagePullPolicy: Always + name: the-app-container + ports: + - containerPort: 80 + serviceAccount: oidc-autologin-angular-12-3652-staging-service-account +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + annotations: + note: Hello, I am staging! + traefik.ingress.kubernetes.io/router.entrypoints: web + labels: + app: oidc-autologin-angular-12-app + org: THNuernberg + variant: staging + name: staging-oidc-autologin-angular-12-ingress +spec: + rules: + - host: kube-master-h4.informatik.fh-nuernberg.de + http: + paths: + - backend: + service: + name: staging-oidc-autologin-angular-12-svc + port: + number: 9605 + path: / + pathType: Prefix diff --git a/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/build-staging.sh b/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/build-staging.sh new file mode 100755 index 0000000..c0ccc7f --- /dev/null +++ b/GIT-Deployment/build-scripts/OIDC-AUTOLOGIN-Angular12/build-staging.sh @@ -0,0 +1,75 @@ +# +# This scripts does the following: +# - Create a YAML File ( DEBUG/kaniko-demo-staging.yaml ) which can be used Gitlab Pipilines to redeploy the APP after commit +# - Deploy the APP a first time to be sure all Resources are created in a proper way +# +# You must loging a first time with gitlab to the kubernetes cluster running a simple kubectl version +# After that you may notice the the first GILLAB login create following resources +# Type Name Namespace kubectl COMMAND +# Namespace kaniko-demo-3492-staging - kubectl get ns +# Serviceaccount kaniko-demo-3492-staging-service-account kaniko-demo-3492-staging kubectl get serviceaccount -n kaniko-demo-3492-staging +# +# For the staging deployment you need to configure following 6 values to reflect your env +# Note: SERVICE-PORT and INGRESS_HOST must be unique at your kubernetes cluster level - so be carefull ! +# CI_PROJECT_NAME must be copied from your GITLAB project +# CI_PROJECT_ID must be copied from your GITLAB project +# CI_REGISTRY_NAME must match your harbor configuration +# KUBE_NAMESPACE is set to the namespace created by GITLAB accessing the Kubernetes cluster a first time +# INGRESS_HOST is set to the external name where the app will be reachable +# Note : Double check the hostname isn't arlready used by a different ingress ( In that case the service will show status pendind ) +# Currentlly following hostnames are configured via DNS for our test cluster +# Hostname Port +# ============== ==== +# kube-master-h1 9601 +# kube-master-h2 9602 +# kube-master-h3 9603 +# kube-master-h4 9604 +# +# In any case we expect that you have create images like with naming syntay <CI_PROJECT_NAME>-<CI_ENVIRONMENT_NAME> like: +# - harbor.informatik.fh-nuernberg.de/hutzler/kaniko-demo-staging +# +CI_PROJECT_NAME=oidc-autologin-angular-12 +CI_PROJECT_ID=3652 +CI_ENVIRONMENT_NAME=staging +SERVICE_PORT=9605 +INGRESS_HOST="kube-master-h4.informatik.fh-nuernberg.de" +CI_REGISTRY_NAME="harbor.informatik.fh-nuernberg.de/hutzler" + +# You don't need to change these values are derived form above paramters +export KUBE_NAMESPACE=$CI_PROJECT_NAME"-"$CI_PROJECT_ID"-"$CI_ENVIRONMENT_NAME +export SERVICE_ACCOUNT=${KUBE_NAMESPACE}-service-account +echo "KUBE_NAMESPACE : " $KUBE_NAMESPACE +echo "SERVICE-ACCOUNT: " $SERVICE_ACCOUNT +echo "INGRESS_HOST: " $INGRESS_HOST +# +CI_REGISTRY_IMAGE=$CI_REGISTRY_NAME"/"$CI_PROJECT_NAME"-"$CI_ENVIRONMENT_NAME +POD_PORT=80 +IMAGE_ESCAPED=$(echo $CI_REGISTRY_IMAGE | sed -r -e 's/\//\\\//g') +echo "Harbor Image to be deployed: " $CI_REGISTRY_IMAGE +# +# +# Resources Naming Stuff - you don'it need to change anything +# +APP_NAME=${CI_PROJECT_NAME}-app +SERVICE_NAME=${CI_PROJECT_NAME}-svc +POD_NAME=${CI_PROJECT_NAME}-pod +INGRESS_NAME=${CI_PROJECT_NAME}-ingress +YAML_FILE=${CI_PROJECT_NAME}"-"${CI_ENVIRONMENT_NAME}.yaml + + +kubectl get serviceaccounts -n ${KUBE_NAMESPACE} + +kustomize build ../../overlays/${CI_ENVIRONMENT_NAME} | sed "s/__SERVICE_NAME__/${SERVICE_NAME}/" | sed "s/__APP_NAME__/${APP_NAME}/" \ + | sed "s/__SERVICE_PORT__/${SERVICE_PORT}/" \ + | sed "s/__POD_NAME__/${POD_NAME}/" | sed "s/__POD_PORT__/${POD_PORT}/" \ + | sed "s/__IMAGE__/${IMAGE_ESCAPED}/" | sed "s/__INGRESS_NAME__/${INGRESS_NAME}/" \ + | sed "s/__INGRESS_HOST__/${INGRESS_HOST}/" \ + | sed "s/__SERVICE_ACCOUNT__/${SERVICE_ACCOUNT}/" > YAML/$YAML_FILE + +kubectl delete --ignore-not-found -f YAML/$YAML_FILE -n $KUBE_NAMESPACE + +kubectl apply -f YAML/$YAML_FILE -n $KUBE_NAMESPACE +sleep 5 + +curl $INGRESS_HOST + -- GitLab