diff --git a/hello-tracing-backend/k8s/deploy b/hello-tracing-backend/k8s/deploy new file mode 100755 index 0000000..2bb25b6 --- /dev/null +++ b/hello-tracing-backend/k8s/deploy @@ -0,0 +1,38 @@ +#!/bin/bash + +usage() { + echo "Deploy to k8s" + echo " -c Context for kubectl" + echo " -v Version of the Docker image, i.e. the value of the tag" + echo " -h Print usage instructions" +} + +while getopts "v:c:h" opt; do + case $opt in + c) + KUBECTL_CONTEXT=$OPTARG + ;; + v) + VERSION=$OPTARG + ;; + h) + usage + exit 0 + ;; + esac +done + +if [ -z "$VERSION" ]; then + VERSION=$(git tag | grep hello-tracing-backend | tr -d 'hello-tracing-backend-' | sort --version-sort -r | head -1 | cut -c 2-) + if [ -z "$VERSION" ]; then + echo "ERROR: cannot determine version" >&2 + exit 1 + fi +fi +export VERSION +echo "Deploying version $VERSION" + +current_dir=$(pwd) +cd $(dirname $0) +kustomize build | envsubst | kubectl apply -f - +cd $current_dir diff --git a/hello-tracing-backend/k8s/hello-tracing-backend.yaml b/hello-tracing-backend/k8s/hello-tracing-backend.yaml new file mode 100644 index 0000000..491efd0 --- /dev/null +++ b/hello-tracing-backend/k8s/hello-tracing-backend.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-tracing-backend-grpc + namespace: hello-tracing +spec: + selector: + app: hello-tracing-backend + ports: + - name: grpc + port: 80 + targetPort: grpc + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-tracing-backend + namespace: hello-tracing +spec: + replicas: 2 + selector: + matchLabels: + app: hello-tracing-backend + template: + metadata: + name: hello-tracing-backend + namespace: hello-tracing + labels: + app: hello-tracing-backend + spec: + containers: + - name: hello-tracing-backend + image: hseeberger/hello-tracing-backend:latest + imagePullPolicy: IfNotPresent + ports: + - name: grpc + containerPort: 8080 + resources: + requests: + cpu: 25m + memory: 25Mi + limits: + cpu: 100m + memory: 100Mi + # readinessProbe: + # grpc: + # port: 8080 diff --git a/hello-tracing-backend/k8s/kustomization.yaml b/hello-tracing-backend/k8s/kustomization.yaml new file mode 100644 index 0000000..28e13fe --- /dev/null +++ b/hello-tracing-backend/k8s/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - hello-tracing-backend.yaml +images: + - name: hseeberger/hello-tracing-backend + newTag: $VERSION diff --git a/hello-tracing-gateway/config/default.yaml b/hello-tracing-gateway/config/default.yaml index 161c158..80c83ec 100644 --- a/hello-tracing-gateway/config/default.yaml +++ b/hello-tracing-gateway/config/default.yaml @@ -2,8 +2,8 @@ api: addr: 0.0.0.0 port: 8080 -backend: - # endpoint: ... +# backend: +# endpoint: ... tracing: service-name: hello-tracing-gateway diff --git a/hello-tracing-gateway/k8s/deploy b/hello-tracing-gateway/k8s/deploy new file mode 100755 index 0000000..df188b5 --- /dev/null +++ b/hello-tracing-gateway/k8s/deploy @@ -0,0 +1,38 @@ +#!/bin/bash + +usage() { + echo "Deploy to k8s" + echo " -c Context for kubectl" + echo " -v Version of the Docker image, i.e. the value of the tag" + echo " -h Print usage instructions" +} + +while getopts "v:c:h" opt; do + case $opt in + c) + KUBECTL_CONTEXT=$OPTARG + ;; + v) + VERSION=$OPTARG + ;; + h) + usage + exit 0 + ;; + esac +done + +if [ -z "$VERSION" ]; then + VERSION=$(git tag | grep hello-tracing-gateway | tr -d 'hello-tracing-gateway-' | sort --version-sort -r | head -1 | cut -c 2-) + if [ -z "$VERSION" ]; then + echo "ERROR: cannot determine version" >&2 + exit 1 + fi +fi +export VERSION +echo "Deploying version $VERSION" + +current_dir=$(pwd) +cd $(dirname $0) +kustomize build | envsubst | kubectl apply -f - +cd $current_dir diff --git a/hello-tracing-gateway/k8s/hello-tracing-gateway.yaml b/hello-tracing-gateway/k8s/hello-tracing-gateway.yaml new file mode 100644 index 0000000..02687f0 --- /dev/null +++ b/hello-tracing-gateway/k8s/hello-tracing-gateway.yaml @@ -0,0 +1,52 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-tracing-gateway-http + namespace: hello-tracing +spec: + selector: + app: hello-tracing-gateway + ports: + - name: http + port: 80 + targetPort: http + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-tracing-gateway + namespace: hello-tracing +spec: + replicas: 2 + selector: + matchLabels: + app: hello-tracing-gateway + template: + metadata: + name: hello-tracing-gateway + namespace: hello-tracing + labels: + app: hello-tracing-gateway + spec: + containers: + - name: hello-tracing-gateway + image: hseeberger/hello-tracing-gateway:latest + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: 8080 + resources: + requests: + cpu: 25m + memory: 25Mi + limits: + cpu: 100m + memory: 100Mi + readinessProbe: + httpGet: + path: / + port: http + env: + - name: APP__BACKEND__ENDPOINT + value: http://hello-tracing-backend-grpc:80 diff --git a/hello-tracing-gateway/k8s/kustomization.yaml b/hello-tracing-gateway/k8s/kustomization.yaml new file mode 100644 index 0000000..f90bb40 --- /dev/null +++ b/hello-tracing-gateway/k8s/kustomization.yaml @@ -0,0 +1,7 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +resources: + - hello-tracing-gateway.yaml +images: + - name: hseeberger/hello-tracing-backend + newTag: $VERSION diff --git a/k8s/hello-tracing.yaml b/k8s/hello-tracing.yaml new file mode 100644 index 0000000..b53325e --- /dev/null +++ b/k8s/hello-tracing.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: hello-tracing + +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: hello-tracing + namespace: hello-tracing + annotations: + cert-manager.io/cluster-issuer: letsencrypt +spec: + ingressClassName: nginx + tls: + - hosts: + - hello-tracing.heikoseeberger.de + secretName: hello-tracing-tls + rules: + - host: hello-tracing.heikoseeberger.de + http: + paths: + - pathType: Prefix + path: / + backend: + service: + name: hello-tracing-gateway-http + port: + name: http