diff --git a/k8s/api.yaml b/k8s/api.yaml new file mode 100644 index 0000000..1f34f8c --- /dev/null +++ b/k8s/api.yaml @@ -0,0 +1,65 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: api + name: api +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: api + template: + metadata: + annotations: + kompose.cmd: kompose convert -f docker-compose.yaml + kompose.version: 1.34.0 (HEAD) + labels: + io.kompose.service: api + spec: + containers: + - env: + - name: COLLECTOR_ENDPOINT + value: http://otel-collector.default.svc.cluster.local:4317 + - name: DATABASE_URL + value: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + - name: POKE_API_BASE_URL + value: https://pokeapi.co/api/v2 + - name: RABBITMQ_HOST + value: guest:guest@queue + - name: REDIS_URL + value: cache + image: kubeshop/demo-pokemon-api:latest + imagePullPolicy: Always + livenessProbe: + exec: + command: + - wget + - --spider + - localhost:8081/pokemon/healthcheck + failureThreshold: 60 + periodSeconds: 1 + timeoutSeconds: 3 + name: api + ports: + - containerPort: 8081 + protocol: TCP + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: api + name: api +spec: + ports: + - name: "8081" + port: 8081 + targetPort: 8081 + selector: + io.kompose.service: api diff --git a/k8s/cache.yaml b/k8s/cache.yaml new file mode 100644 index 0000000..563703d --- /dev/null +++ b/k8s/cache.yaml @@ -0,0 +1,49 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: cache + name: cache +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: cache + template: + metadata: + labels: + io.kompose.service: cache + spec: + containers: + - image: redis:6 + livenessProbe: + exec: + command: + - redis-cli + - ping + failureThreshold: 60 + periodSeconds: 1 + timeoutSeconds: 3 + name: cache + ports: + - containerPort: 6379 + protocol: TCP + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: cache + name: cache +spec: + ports: + - name: "6379" + port: 6379 + targetPort: 6379 + selector: + io.kompose.service: cache diff --git a/k8s/db.yaml b/k8s/db.yaml new file mode 100644 index 0000000..e8d08b2 --- /dev/null +++ b/k8s/db.yaml @@ -0,0 +1,89 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: db + name: db +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: db + template: + metadata: + labels: + io.kompose.service: db + spec: + containers: + - env: + - name: POSTGRES_DB + value: pokeshop + - name: POSTGRES_PASSWORD + value: squirtle123 + - name: POSTGRES_USER + value: ashketchum + image: postgres:14 + name: db + ports: + - containerPort: 5432 + protocol: TCP + volumeMounts: + - mountPath: /var/lib/postgresql/data + name: dbdata + volumes: + - name: dbdata + persistentVolumeClaim: + claimName: db-volume-claim + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: db + name: db +spec: + ports: + - name: "5432" + port: 5432 + targetPort: 5432 + selector: + io.kompose.service: db + +# Persistent Volume +--- +apiVersion: v1 +kind: PersistentVolume +metadata: + name: db-volume + labels: + type: local + io.kompose.service: db +spec: + storageClassName: manual + capacity: + storage: 10Gi + accessModes: + - ReadWriteMany + hostPath: + path: /data/postgresql + +# Persistent Volume Claim +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: db-volume-claim + labels: + io.kompose.service: db +spec: + storageClassName: manual + accessModes: + - ReadWriteMany + resources: + requests: + storage: 10Gi diff --git a/k8s/jaeger.yaml b/k8s/jaeger.yaml new file mode 100644 index 0000000..6d3d840 --- /dev/null +++ b/k8s/jaeger.yaml @@ -0,0 +1,70 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: jaeger + name: jaeger +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: jaeger + template: + metadata: + labels: + io.kompose.service: jaeger + spec: + containers: + - env: + - name: COLLECTOR_OTLP_ENABLED + value: "true" + - name: COLLECTOR_ZIPKIN_HOST_PORT + value: :9411 + image: jaegertracing/all-in-one:latest + livenessProbe: + exec: + command: + - wget + - --spider + - localhost:16686 + failureThreshold: 60 + periodSeconds: 1 + timeoutSeconds: 3 + name: jaeger + ports: + - containerPort: 4317 + protocol: TCP + - containerPort: 14250 + protocol: TCP + - containerPort: 16685 + protocol: TCP + - containerPort: 16686 + protocol: TCP + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: jaeger + name: jaeger +spec: + ports: + - name: "4317" + port: 4317 + targetPort: 4317 + - name: "14250" + port: 14250 + targetPort: 14250 + - name: "16685" + port: 16685 + targetPort: 16685 + - name: "16686" + port: 16686 + targetPort: 16686 + selector: + io.kompose.service: jaeger diff --git a/k8s/otel-collector.yaml b/k8s/otel-collector.yaml new file mode 100644 index 0000000..1e2c460 --- /dev/null +++ b/k8s/otel-collector.yaml @@ -0,0 +1,119 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: otel-collector + name: otel-collector +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: otel-collector + strategy: + type: Recreate + template: + metadata: + labels: + io.kompose.service: otel-collector + spec: + containers: + - args: + - --config + - /config/otel-local-config.yaml + env: + - name: JAEGER_ENDPOINT + value: jaeger.default.svc.cluster.local:4317 + - name: TRACETEST_AGENT_ENDPOINT + value: tracetest-agent.default.svc.cluster.local:4317 + image: otel/opentelemetry-collector-contrib:0.107.0 + name: otel-collector + ports: + - containerPort: 55679 + protocol: TCP + - containerPort: 8888 + protocol: TCP + - containerPort: 4317 + protocol: TCP + - containerPort: 4318 + protocol: TCP + volumeMounts: + - mountPath: /config + name: otel-collector-cm0 + restartPolicy: Always + volumes: + - configMap: + items: + - key: collector.config.yaml + path: otel-local-config.yaml + name: otel-collector-cm0 + name: otel-collector-cm0 + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: otel-collector + name: otel-collector +spec: + ports: + - name: "55679" + port: 55679 + targetPort: 55679 + - name: "8888" + port: 8888 + targetPort: 8888 + - name: "4317" + port: 4317 + targetPort: 4317 + - name: "4318" + port: 4318 + targetPort: 4318 + selector: + io.kompose.service: otel-collector + +# ConfigMap +--- +apiVersion: v1 +data: + collector.config.yaml: | + receivers: + otlp: + protocols: + grpc: + endpoint: 0.0.0.0:4317 + http: + endpoint: 0.0.0.0:4318 + processors: + batch: + exporters: + logging: + loglevel: debug + otlp/jaeger: + endpoint: ${JAEGER_ENDPOINT} + tls: + insecure: true + otlp/tracetest: + endpoint: ${TRACETEST_AGENT_ENDPOINT} + tls: + insecure: true + service: + pipelines: + traces/jaeger: + receivers: [otlp] + processors: [] + exporters: [logging, otlp/jaeger] + traces/tracetest: + receivers: [otlp] + processors: [batch] + exporters: [otlp/tracetest] +kind: ConfigMap +metadata: + annotations: + use-subpath: "true" + labels: + io.kompose.service: otel-collector + name: otel-collector-cm0 diff --git a/k8s/queue.yaml b/k8s/queue.yaml new file mode 100644 index 0000000..535111b --- /dev/null +++ b/k8s/queue.yaml @@ -0,0 +1,53 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: queue + name: queue +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: queue + template: + metadata: + labels: + io.kompose.service: queue + spec: + containers: + - image: rabbitmq:3.12 + livenessProbe: + exec: + command: + - rabbitmq-diagnostics -q check_running + failureThreshold: 60 + periodSeconds: 1 + timeoutSeconds: 5 + name: queue + ports: + - containerPort: 5672 + protocol: TCP + - containerPort: 15672 + protocol: TCP + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: queue + name: queue +spec: + ports: + - name: "5672" + port: 5672 + targetPort: 5672 + - name: "15672" + port: 15672 + targetPort: 15672 + selector: + io.kompose.service: queue diff --git a/k8s/readme.md b/k8s/readme.md new file mode 100644 index 0000000..c20fb20 --- /dev/null +++ b/k8s/readme.md @@ -0,0 +1,19 @@ +# Install Pokeshop with K8s Manifests + +1. [Get your Tracetest API key and env id](https://app.tracetest.io/retrieve-token) +2. Add your API key and env id in the `tracetest-agent.yaml` +3. Apply all resources + + ```bash + kubectl apply -f . + ``` +4. Create and run a test by going to [`app.tracetest.io`](https://app.tracetest.io) and using the internal Kubernetes service networking: + + - **POST** `http://api.default.svc.cluster.local:8081/pokemon/import` - Body: `{ "id": 1 }` + - **GET** `http://api.default.svc.cluster.local:8081/pokemon` + + ![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1724764008/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_4b0e8945dbe5045a_test_tTFZ453Ig_run_9_selectedSpan_bb8ba205b42a8619_nylqid.png) + +5. View the trace and create test specs by going to the `Test` tab. + + ![](https://res.cloudinary.com/djwdcmwdz/image/upload/v1724764098/docs/app.tracetest.io_organizations_ttorg_e66318ba6544b856_environments_ttenv_4b0e8945dbe5045a_test_tTFZ453Ig_run_9_selectedSpan_bb8ba205b42a8619_1_xaxlbi.png) \ No newline at end of file diff --git a/k8s/rpc.yaml b/k8s/rpc.yaml new file mode 100644 index 0000000..aeebb4e --- /dev/null +++ b/k8s/rpc.yaml @@ -0,0 +1,66 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: rpc + name: rpc +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: rpc + template: + metadata: + labels: + io.kompose.service: rpc + spec: + containers: + - env: + - name: NPM_RUN_COMMAND + value: rpc + - name: COLLECTOR_ENDPOINT + value: http://otel-collector.default.svc.cluster.local:4317 + - name: DATABASE_URL + value: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + - name: POKE_API_BASE_URL + value: https://pokeapi.co/api/v2 + - name: RABBITMQ_HOST + value: guest:guest@queue + - name: REDIS_URL + value: cache + - name: RPC_PORT + value: "8082" + image: kubeshop/demo-pokemon-api:latest + imagePullPolicy: Always + livenessProbe: + exec: + command: + - wget + - --spider + - 0.0.0.0:8081/pokemon/healthcheck + failureThreshold: 60 + periodSeconds: 1 + timeoutSeconds: 3 + name: rpc + ports: + - containerPort: 8082 + protocol: TCP + restartPolicy: Always + +# Service +--- +apiVersion: v1 +kind: Service +metadata: + labels: + io.kompose.service: rpc + name: rpc +spec: + ports: + - name: "8082" + port: 8082 + targetPort: 8082 + selector: + io.kompose.service: rpc diff --git a/k8s/tracetest-agent.yaml b/k8s/tracetest-agent.yaml new file mode 100644 index 0000000..b95380f --- /dev/null +++ b/k8s/tracetest-agent.yaml @@ -0,0 +1,59 @@ +--- +# Service +apiVersion: v1 +kind: Service +metadata: + name: tracetest-agent + labels: + app.kubernetes.io/name: tracetest-agent + app.kubernetes.io/instance: tracetest-agent +spec: + selector: + app.kubernetes.io/name: tracetest-agent + app.kubernetes.io/instance: tracetest-agent + ports: + - name: grpc-collector-entrypoint + protocol: TCP + port: 4317 + targetPort: 4317 + - name: http-collector-entrypoint + protocol: TCP + port: 4318 + targetPort: 4318 +--- +# Deployment +apiVersion: apps/v1 +kind: Deployment +metadata: + name: tracetest-agent + labels: + app: tracetest-agent + app.kubernetes.io/name: tracetest-agent + app.kubernetes.io/instance: tracetest-agent +spec: + selector: + matchLabels: + app.kubernetes.io/name: tracetest-agent + app.kubernetes.io/instance: tracetest-agent + template: + metadata: + labels: + app.kubernetes.io/name: tracetest-agent + app.kubernetes.io/instance: tracetest-agent + spec: + containers: + - name: agent + image: "kubeshop/tracetest-agent:latest" + imagePullPolicy: Always + args: [ + "--environment", + "", # Add your env id + "--api-key", + "$TRACETEST_API_KEY", + "--server-url", + "https://app.tracetest.io", + "--mode='verbose'", + ] + env: + - name: TRACETEST_API_KEY + value: "" # Add your API key diff --git a/k8s/worker.yaml b/k8s/worker.yaml new file mode 100644 index 0000000..a600a69 --- /dev/null +++ b/k8s/worker.yaml @@ -0,0 +1,36 @@ +# Deployment +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + io.kompose.service: worker + name: worker +spec: + replicas: 1 + selector: + matchLabels: + io.kompose.service: worker + template: + metadata: + labels: + io.kompose.service: worker + spec: + containers: + - env: + - name: NPM_RUN_COMMAND + value: worker + - name: COLLECTOR_ENDPOINT + value: http://otel-collector.default.svc.cluster.local:4317 + - name: DATABASE_URL + value: postgresql://ashketchum:squirtle123@db:5432/pokeshop?schema=public + - name: POKE_API_BASE_URL + value: https://pokeapi.co/api/v2 + - name: RABBITMQ_HOST + value: guest:guest@queue + - name: REDIS_URL + value: cache + image: kubeshop/demo-pokemon-api:latest + imagePullPolicy: Always + name: worker + restartPolicy: Always