Skip to content

Commit

Permalink
ops: add k8s resources (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
hseeberger authored Nov 17, 2023
1 parent 37d5c23 commit ca176cf
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 2 deletions.
38 changes: 38 additions & 0 deletions hello-tracing-backend/k8s/deploy
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions hello-tracing-backend/k8s/hello-tracing-backend.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions hello-tracing-backend/k8s/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions hello-tracing-gateway/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ api:
addr: 0.0.0.0
port: 8080

backend:
# endpoint: ...
# backend:
# endpoint: ...

tracing:
service-name: hello-tracing-gateway
Expand Down
38 changes: 38 additions & 0 deletions hello-tracing-gateway/k8s/deploy
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions hello-tracing-gateway/k8s/hello-tracing-gateway.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions hello-tracing-gateway/k8s/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions k8s/hello-tracing.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ca176cf

Please sign in to comment.