Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Simple kubernetes setup #210

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,81 @@ build-docker-images:
.PHONY: push-docker-images
push-docker-images:
docker compose -f docker-compose.yml push


.PHONY: k8s_local_apply_db
k8s_local_apply_db:
kubectl apply -f k8s_local/redis.yaml
kubectl apply -f k8s_local/postgres.yaml
kubectl apply -f k8s_local/jaeger.yaml
kubectl apply -f k8s_local/prometheus.yaml
kubectl apply -f k8s_local/grafana.yaml
kubectl apply -f k8s_local/otel-agent-daemonset.yaml

.PHONY: k8s_local_clean_db
k8s_local_clean_db:
kubectl delete deployment redis
kubectl delete deployment postgres
kubectl delete deployment jaeger
kubectl delete deployment prometheus
kubectl delete deployment grafana
kubectl delete daemonset otel-agent
kubectl delete configmaps otel-agent-config
kubectl delete configmaps prometheus-config
kubectl delete configmaps grafana-config
kubectl delete configmaps grafana-provisioning
kubectl delete svc redis
kubectl delete svc postgres
kubectl delete svc jaeger
kubectl delete svc prometheus
kubectl delete svc grafana
kubectl delete svc otel-agent


.PHONY: k8s_local_apply_services
k8s_local_apply_services:
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/adservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/cartservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/checkoutservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/currencyservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/emailservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/featureflagservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/frontend.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/paymentservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/productcatalogservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/recommendationservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/shippingservice.yaml | kubectl apply -f -
DOCKER_IMAGE_VERSION=v0.2.0-alpha envsubst < k8s_local/loadgenerator.yaml | kubectl apply -f -

.PHONY: k8s_local_clean_services
k8s_local_clean_services:
kubectl delete deployment loadgenerator
kubectl delete deployment adservice
kubectl delete deployment cartservice
kubectl delete deployment checkoutservice
kubectl delete deployment currencyservice
kubectl delete deployment emailservice
kubectl delete deployment featureflagservice
kubectl delete deployment frontend
kubectl delete deployment paymentservice
kubectl delete deployment productcatalogservice
kubectl delete deployment recommendationservice
kubectl delete deployment shippingservice
kubectl delete svc adservice
kubectl delete svc cartservice
kubectl delete svc checkoutservice
kubectl delete svc currencyservice
kubectl delete svc emailservice
kubectl delete svc featureflagservice
kubectl delete svc frontend
kubectl delete svc paymentservice
kubectl delete svc productcatalogservice
kubectl delete svc recommendationservice
kubectl delete svc shippingservice


.PHONY: k8s_local_apply
k8s_local_apply: k8s_local_apply_db k8s_local_apply_services

.PHONY: k8s_local_clean
k8s_local_clean: k8s_local_clean_services k8s_local_clean_db
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,42 @@ Find the **Protocol Buffer Definitions** in the `/pb/` directory.
| [featureflagservice](./src/featureflagservice/README.md) | Erlang/Elixir | CRUD feature flag service to demonstrate various scenarios like fault injection & how to emit telemetry from a feature flag reliant service. |
| [loadgenerator](./src/loadgenerator/README.md) | Python/Locust | Continuously sends requests imitating realistic user shopping flows to the frontend. |

## Running on Kubernetes

To Run the demo on kubernetes cluseter locally like minikube or docker
kubernetes, we can apply the config present in `k8s_local` directory.
Please be aware that this will deploy the application to the context.
`kubectl` is set to.

```shell
make k8s_local_apply
```

We can port-forward to view ui, prometheus , jaeger & grafana .
We can do port-forward to the services using the script.

```shell
k8s_local/port_forward.sh
```

Once the port-forward is successful we can view

- Webstore: <http://localhost:8080/>

- Jaeger: <http://localhost:16686/>

- Prometheus: <http://localhost:9090/>

- Grafana: <http://localhost:3000/>

To clean up the setup from kubernetes cluster run the command.
Please make sure you are using right kubernetes context.
The command will fail at first error

```shell
make k8s_local_clean
```

## Features

- **[Kubernetes](https://kubernetes.io)**: the app is designed to run on
Expand Down
75 changes: 75 additions & 0 deletions k8s_local/adservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: adservice
labels:
app: adservice
component: otel-demo-adservice
spec:
replicas: 1
selector:
matchLabels:
app: adservice
component: otel-demo-adservice
template:
metadata:
labels:
service: adservice
app: adservice
component: otel-demo-adservice
spec:
containers:
- name: adservice
image: otel/demo:${DOCKER_IMAGE_VERSION}-adservice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following #156, the package is now public, we could use ghcr.io/open-telemetry/demo now.

imagePullPolicy: Always
resources:
limits:
memory: 200Mi
cpu: 100m
requests:
memory: 200Mi
cpu: 100m
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: OTEL_RESOURCE
value: k8s.pod.ip=$(MY_POD_IP)
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_AGENT_ENDPOINT
value: "$(HOST_IP)"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4318"
- name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4317"
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=adservice,deployment.environment=staging"
- name: APP_ENV
value: staging
- name: AD_SERVICE_PORT
value: "9555"
---
apiVersion: v1
kind: Service
metadata:
name: adservice
labels:
app: adservice
component: otel-demo-adservice
spec:
clusterIP: None
type: ClusterIP
ports:
- port: 9555
protocol: TCP
name: http
selector:
app: adservice
component: otel-demo-adservice
---
79 changes: 79 additions & 0 deletions k8s_local/cartservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: cartservice
labels:
app: cartservice
component: otel-demo-cartservice
spec:
replicas: 1
selector:
matchLabels:
app: cartservice
component: otel-demo-cartservice
template:
metadata:
labels:
service: cartservice
app: cartservice
component: otel-demo-cartservice
spec:
containers:
- name: cartservice
image: otel/demo:${DOCKER_IMAGE_VERSION}-cartservice
imagePullPolicy: Always
resources:
limits:
memory: 200Mi
cpu: 100m
requests:
memory: 200Mi
cpu: 100m
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: OTEL_RESOURCE
value: k8s.pod.ip=$(MY_POD_IP)
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_AGENT_ENDPOINT
value: "$(HOST_IP)"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4318"
- name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4317"
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=cartservice,deployment.environment=staging"
- name: APP_ENV
value: staging
- name: CART_SERVICE_PORT
value: "7070"
- name: ASPNETCORE_URLS
value: "http://*:$(CART_SERVICE_PORT)"
- name: REDIS_ADDR
value: "redis"
---
apiVersion: v1
kind: Service
metadata:
name: cartservice
labels:
app: cartservice
component: otel-demo-cartservice
spec:
clusterIP: None
type: ClusterIP
ports:
- port: 7070
protocol: TCP
name: http
selector:
app: cartservice
component: otel-demo-cartservice
---
100 changes: 100 additions & 0 deletions k8s_local/checkoutservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: checkoutservice
labels:
app: checkoutservice
component: otel-demo-checkoutservice
spec:
replicas: 1
selector:
matchLabels:
app: checkoutservice
component: otel-demo-checkoutservice
template:
metadata:
labels:
service: checkoutservice
app: checkoutservice
component: otel-demo-checkoutservice
spec:
containers:
- name: checkoutservice
image: otel/demo:${DOCKER_IMAGE_VERSION}-checkoutservice
imagePullPolicy: Always
resources:
limits:
memory: 200Mi
cpu: 100m
requests:
memory: 200Mi
cpu: 100m
env:
- name: MY_POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: OTEL_RESOURCE
value: k8s.pod.ip=$(MY_POD_IP)
- name: HOST_IP
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OTEL_AGENT_ENDPOINT
value: "$(HOST_IP)"
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4318"
- name: OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
value: "http://$(OTEL_AGENT_ENDPOINT):4317"
- name: OTEL_RESOURCE_ATTRIBUTES
value: "service.name=checkoutservice,
deployment.environment=staging"
- name: APP_ENV
value: staging
- name: CHECKOUT_SERVICE_PORT
value: "5050"
- name: CART_SERVICE_PORT
value: "7070"
- name: CART_SERVICE_ADDR
value: "cartservice:$(CART_SERVICE_PORT)"
- name: CURRENCY_SERVICE_PORT
value: "7000"
- name: CURRENCY_SERVICE_ADDR
value: "currencyservice:$(CURRENCY_SERVICE_PORT)"
- name: EMAIL_SERVICE_PORT
value: "8080"
- name: EMAIL_SERVICE_ADDR
value: "http://emailservice:$(EMAIL_SERVICE_PORT)"
- name: PAYMENT_SERVICE_PORT
value: "50051"
- name: PAYMENT_SERVICE_ADDR
value: "paymentservice:$(PAYMENT_SERVICE_PORT)"
- name: PRODUCT_CATALOG_SERVICE_PORT
value: "3550"
- name: PRODUCT_CATALOG_SERVICE_ADDR
value: "productcatalogservice:$(PRODUCT_CATALOG_SERVICE_PORT)"
- name: SHIPPING_SERVICE_PORT
value: "50051"
- name: SHIPPING_SERVICE_ADDR
value: "shippingservice:$(SHIPPING_SERVICE_PORT)"
---
apiVersion: v1
kind: Service
metadata:
name: checkoutservice
labels:
app: checkoutservice
component: otel-demo-checkoutservice
spec:
clusterIP: None
type: ClusterIP
ports:
- port: 5050
protocol: TCP
name: http
selector:
app: checkoutservice
component: otel-demo-checkoutservice
---
Loading