Skip to content

Commit

Permalink
fix: running on kubernetes
Browse files Browse the repository at this point in the history
  • Loading branch information
mati007thm committed Dec 15, 2023
1 parent cb9a07f commit c991816
Show file tree
Hide file tree
Showing 424 changed files with 677 additions and 49 deletions.
2 changes: 1 addition & 1 deletion dapr-distributed-calendar/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
# Node app + Dapr sidecar
############################
controller:
build: .
build: ./node
ports:
- "3000:3000"
- "3500"
Expand Down
34 changes: 1 addition & 33 deletions dapr-distributed-calendar/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
# # Use an official Golang runtime as a parent image
# FROM golang:1.16-alpine

# # Set the working directory to /app
# WORKDIR /app

# # Copy only the Go application code to the container
# COPY go_events.go .

# # go mod init
# RUN go mod init app

# # Install gorilla/mux package
# RUN go get -u github.com/gorilla/mux

# # Install Dapr
# RUN apk add --no-cache bash \
# && wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash \
# && apk del --no-cache bash

# # Build the go_events executable
# RUN go build -o go_events go_events.go

# # Set environment variables
# ENV DAPR_HTTP_PORT 3503
# ENV APP_PORT 6000
# ENV APP_ID go-events

# # Command to run the executable
# # CMD ["dapr", "run", "--app-id", "${APP_ID}", "--app-port", "${APP_PORT}", "--dapr-http-port", "${DAPR_HTTP_PORT}", "./go_events"]

# CMD sh -c "dapr run --app-id ${APP_ID} --app-port ${APP_PORT} --dapr-http-port ${DAPR_HTTP_PORT} ./go_events"

#first stage - builder
FROM golang:1.15-buster as builder
WORKDIR /dir
Expand All @@ -41,4 +8,5 @@ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .
FROM debian:buster-slim
WORKDIR /root/
COPY --from=builder /dir/app .
EXPOSE 6000
CMD ["./app"]
1 change: 1 addition & 0 deletions dapr-distributed-calendar/go/go_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Event struct {
}

func addEvent(w http.ResponseWriter, r *http.Request) {
log.Printf(stateURL)
var event Event

err := json.NewDecoder(r.Body).Decode(&event)
Expand Down
4 changes: 4 additions & 0 deletions dapr-distributed-calendar/jaeger/simplest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: simplest
87 changes: 87 additions & 0 deletions dapr-distributed-calendar/kubernetes-deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/sh

# # Replace
# find kubernetes* -type f -exec sed -i -e "s//$USER_ID/g" {} \;

# # Replace
# find kubernetes* -type f -exec sed -i -e "s//$ANIMAL/g" {} \;

# # Replace
# find kubernetes* -type f -exec sed -i -e "s//$HOST_IP/g" {} \;

# # Replace
# find kubernetes* -type f -exec sed -i -e "s//$ENVIRONMENT/g" {} \;

# # Replace
# find kubernetes* -type f -exec sed -i -e "s//$DOMAIN/g" {} \;

# create namespace
# kubectl create namespace 12-factor-app

# create OTel collector
# helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
# helm repo update
# helm upgrade --install my-opentelemetry-collector open-telemetry/opentelemetry-collector \
# --set mode=deployment \
# --values otel/otel-collector-values.yaml
# --namespace 12-factor-app

# install OTel Operator
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo update
helm install my-opentelemetry-operator open-telemetry/opentelemetry-operator \
--set admissionWebhooks.certManager.enabled=false \
--set admissionWebhooks.certManager.autoGenerateCert.enabled=true \
--wait

# create OTel collector and instrumentation
kubectl apply -f otel/.

# install cert-manager
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm upgrade --install \
cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.7.1 \
--set installCRDs=true \
--wait

# install jaeger
kubectl create namespace observability
kubectl create -f https://github.com/jaegertracing/jaeger-operator/releases/download/v1.38.0/jaeger-operator.yaml -n observability --wait
kubectl apply -f jaeger/simplest.yaml --wait

# install prometheus
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack \
--version 51.3.0 \
--namespace default \
--values prometheus/kube-prometheus-stack-values.yaml \
--wait

# install dapr
helm repo add dapr https://dapr.github.io/helm-charts/
helm repo update
helm upgrade --install dapr dapr/dapr \
--namespace dapr-system \
--create-namespace \
--set global.logAsJson=true \
--wait

# install dapr dashboard
helm install dapr-dashboard dapr/dapr-dashboard --namespace dapr-system --wait

# install redis
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install redis bitnami/redis --wait
# helm install redis bitnami/redis --set image.tag=6.2 -f redis/values.yaml --wait

# deploy the 12-factor-app
kubectl apply -f kubernetes/.

# get redis password
kubectl get secret redis -o jsonpath='{.data.redis-password}' | base64 --decode
26 changes: 26 additions & 0 deletions dapr-distributed-calendar/kubernetes/appconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: appconfig
# namespace: 12-factor-app
spec:
tracing:
samplingRate: "1"
stdout: true
otel:
endpointAddress: otel-dapr-collector:4317
isSecure: false
protocol: grpc
# metrics:
# enabled: true
# rules:
# - name: dapr_runtime_service_invocation_req_sent_total
# labels:
# - name: method
# regex:
# "orders/": "orders/.+" # match all methods under orders
# logging:
# apiLogging:
# enabled: true
# obfuscateURLs: true
# omitHealthChecks: true
44 changes: 44 additions & 0 deletions dapr-distributed-calendar/kubernetes/go-events.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-events
# namespace: 12-factor-app
labels:
app: go-events
spec:
replicas: 1
selector:
matchLabels:
app: go-events
template:
metadata:
labels:
app: go-events
annotations:
instrumentation.opentelemetry.io/inject-go: "go-instrumentation"
instrumentation.opentelemetry.io/otel-go-auto-target-exe: '/root/'
dapr.io/enabled: "true"
dapr.io/app-id: "go-events"
dapr.io/app-port: "6000"
dapr.io/config: "appconfig"
dapr.io/log-as-json: "true"
# our daprd memory settings
# dapr.io/sidecar-memory-limit: "1000Mi" # your memory limit
# dapr.io/env: "GOMEMLIMIT=900MiB" # 90% of your memory limit. Also notice the suffix "MiB" instead of "Mi"
spec:
containers:
- name: go-events
image: mati007thm/dapr-distributed-calendar_go-events:latest
env:
- name: APP_PORT
value: "6000"
- name: DAPR_HTTP_PORT
value: "3500"
- name: OTEL_SERVICE_NAME
value: "go-events"
ports:
- containerPort: 6000
imagePullPolicy: Always
securityContext:
runAsUser: 0
privileged: true
14 changes: 14 additions & 0 deletions dapr-distributed-calendar/kubernetes/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# apiVersion: traefik.containo.us/v1alpha1
# kind: IngressRoute
# metadata:
# name: controller-ingress
# namespace: 12-factor-app
# spec:
# entryPoints:
# - web
# routes:
# - match: Host(`controller.<ENV-NAME>-<ENV-USER-ID>-01.<ENV-ANIMAL>.<ENV-DOMAIN>`) && PathPrefix(`/`)
# kind: Rule
# services:
# - name: controller
# port: 80
54 changes: 54 additions & 0 deletions dapr-distributed-calendar/kubernetes/node-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
kind: Service
apiVersion: v1
metadata:
name: controller
# namespace: 12-factor-app
labels:
app: controller
spec:
selector:
app: controller
ports:
- protocol: TCP
port: 3000
targetPort: 3000
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller
# namespace: 12-factor-app
labels:
app: controller
spec:
replicas: 1
selector:
matchLabels:
app: controller
template:
metadata:
labels:
app: controller
annotations:
instrumentation.opentelemetry.io/inject-nodejs: "node-instrumentation"
dapr.io/enabled: "true"
dapr.io/app-id: "controller"
dapr.io/app-port: "3000"
dapr.io/config: "appconfig"
dapr.io/log-as-json: "true"
# our daprd memory settings
# dapr.io/sidecar-memory-limit: "1000Mi" # your memory limit
# dapr.io/env: "GOMEMLIMIT=900MiB" # 90% of your memory limit. Also notice the suffix "MiB" instead of "Mi"
spec:
containers:
- name: controller
image: mati007thm/dapr-distributed-calendar_controller:latest
env:
- name: APP_PORT
value: "3000"
- name: OTEL_SERVICE_NAME
value: "controller"
ports:
- containerPort: 3000
imagePullPolicy: Always
40 changes: 40 additions & 0 deletions dapr-distributed-calendar/kubernetes/python-messages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: messages
# namespace: 12-factor-app
labels:
app: messages
spec:
replicas: 1
selector:
matchLabels:
app: messages
template:
metadata:
labels:
app: messages
annotations:
# instrumentation.opentelemetry.io/inject-python: "python-instrumentation"
dapr.io/enabled: "true"
dapr.io/app-id: "messages"
dapr.io/app-port: "5000"
dapr.io/config: "appconfig"
dapr.io/log-as-json: "true"
# our daprd memory settings
# dapr.io/sidecar-memory-limit: "1000Mi" # your memory limit
# dapr.io/env: "GOMEMLIMIT=900MiB" # 90% of your memory limit. Also notice the suffix "MiB" instead of "Mi"
spec:
containers:
- name: messages
image: mati007thm/dapr-distributed-calendar_messages:latest
env:
- name: "APP_PORT"
value: "5000"
- name: FLASK_RUN_PORT
value: "5000"
# - name: OTEL_SERVICE_NAME
# value: "messages"
ports:
- containerPort: 5000
imagePullPolicy: Always
37 changes: 37 additions & 0 deletions dapr-distributed-calendar/kubernetes/redis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: events
# namespace: 12-factor-app
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: redis-master:6379
- name: redisPassword
# value: "jW6UBn6aea" # kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode
secretKeyRef:
name: redis
key: redis-password
auth:
secretStore: kubernetes
---
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
# namespace: 12-factor-app
spec:
type: pubsub.redis
version: v1
metadata:
- name: redisHost
value: redis-master:6379
- name: redisPassword
# value: "jW6UBn6aea" # kubectl get secret --namespace default redis -o jsonpath="{.data.redis-password}" | base64 --decode
secretKeyRef:
name: redis
key: redis-password
auth:
secretStore: kubernetes
Loading

0 comments on commit c991816

Please sign in to comment.