From 547cd78456053837c173f654aad222a41a6168a1 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 13 Oct 2020 11:47:50 +0200 Subject: [PATCH] contrib/kubernetes: added plain single pod deployment example --- .github/styles/vocab.txt | 1 + .../plain_single_backend_deplyoment/README.md | 42 +++++++ .../deployment.yaml | 108 ++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 contrib/kubernetes/plain_single_backend_deplyoment/README.md create mode 100644 contrib/kubernetes/plain_single_backend_deplyoment/deployment.yaml diff --git a/.github/styles/vocab.txt b/.github/styles/vocab.txt index 6a2eecdee0..40346fc0e8 100644 --- a/.github/styles/vocab.txt +++ b/.github/styles/vocab.txt @@ -105,6 +105,7 @@ Monorepo monorepos msw namespace +namespaces Namespaces neuro newrelic diff --git a/contrib/kubernetes/plain_single_backend_deplyoment/README.md b/contrib/kubernetes/plain_single_backend_deplyoment/README.md new file mode 100644 index 0000000000..685bed92a5 --- /dev/null +++ b/contrib/kubernetes/plain_single_backend_deplyoment/README.md @@ -0,0 +1,42 @@ +# Plain Kubernetes Deployment + +This directory contains an example of a simple Kubernetes deployment of Backstage. It is not intended to serve as a complete production deployment, but as a starting point for setting one up. + +## Usage + +You can try the deployment out as is. The easiest way is to use [Docker Desktop](https://www.docker.com/products/docker-desktop) with [Kubernetes](https://docs.docker.com/get-started/kube-deploy/). + +From a fresh clone of this repo, run the following in the root: + +```bash +yarn install + +yarn docker-build + +kubectl apply -f contrib/kubernetes/plain_single_backend_deplyoment/deployment.yaml +``` + +You can use the following commands to monitor the deployment: + +```bash +# List all resources in the backstage namespace +kubectl -n backstage get all + +# Inspect the status of the deployment resource +kubectl -n backstage describe deployment backstage-backend + +# Inspect the status of the pod running the backstage backend +kubectl -n backstage describe pod -l app=backstage,component=backend +``` + +Once the deployment is up and running, you can use the following to set up a proxy to reach the backend locally: + +```bash +kubectl proxy +``` + +With the proxy up and running, you should be able to navigate to [http://localhost:8001/api/v1/namespaces/backstage/services/backstage-backend:http/proxy](http://localhost:8001/api/v1/namespaces/backstage/services/backstage-backend:http/proxy) and see Backstage. Note that you'll end up on a 404 page, but hitting the home icon in the sidebar should take you to the catalog page where you can see a few example services. + +## Caveats + +This deployment is for demonstration purposes only, for a production deployment you will need to set up at least a persistent database and some form of ingress. If your organization doesn't already have established patterns for these, you could look at options of managed PostgreSQL instances from cloud providers, or something like Zalando's [postgres-operator](https://github.com/zalando/postgres-operator). For ingress there are also [plenty of options](https://ramitsurana.gitbook.io/awesome-kubernetes/docs/projects/projects#load-balancing), where `nginx` is a popular choice to get started. diff --git a/contrib/kubernetes/plain_single_backend_deplyoment/deployment.yaml b/contrib/kubernetes/plain_single_backend_deplyoment/deployment.yaml new file mode 100644 index 0000000000..87dee94895 --- /dev/null +++ b/contrib/kubernetes/plain_single_backend_deplyoment/deployment.yaml @@ -0,0 +1,108 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: backstage +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: backstage-backend + namespace: backstage +spec: + replicas: 1 + selector: + matchLabels: + app: backstage + component: backend + template: + metadata: + labels: + app: backstage + component: backend + spec: + containers: + - name: backend + # This image is built with `yarn docker-build` in the repo root. + # Replace this with your own image to deploy your own Backstage app. + image: example-backend:latest + imagePullPolicy: Never + + env: + # We set this to development to make the backend start with incomplete configuration. In a production + # deployment you will want to make sure that you have a full configuration, and remove any plugins that + # you are not using. + - name: NODE_ENV + value: development + + # This makes us load in `app-config.production.yaml` if there is one. + - name: APP_ENV + value: production + + # This makes it possible for the app to reach the backend when serving through `kubectl proxy` + # If you expose the service using for example an ingress controller, you should + # switch this out or remove it. + # + # Note that we're not setting app.baseUrl here, as setting the base path is not working at the moment. + # Further work is needed around the routing in the frontend or react-router before we can support that. + - name: APP_CONFIG_backend_baseUrl + value: http://localhost:8001/api/v1/namespaces/backstage/services/backstage-backend:http/proxy + + ports: + - name: http + containerPort: 7000 + + volumeMounts: + - name: config-volume + mountPath: /usr/src/app/app-config.local.yaml + subPath: app-config.local.yaml + + resources: + limits: + cpu: 1 + memory: 0.5Gi + + readinessProbe: + httpGet: + port: 7000 + path: /healthcheck + livenessProbe: + httpGet: + port: 7000 + path: /healthcheck + + volumes: + - name: config-volume + configMap: + name: backstage-config + items: + - key: app-config + path: app-config.local.yaml +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: backstage-config + namespace: backstage +data: + # Note that the config here is only applied to the backend. The frontend config is applied at build time. + # To override frontend config in this deployment, use `APP_CONFIG_` env vars. + app-config: | + app: + baseUrl: http://localhost:8001/api/v1/namespaces/backstage/services/backstage-backend:http/proxy + backend: + baseUrl: http://localhost:8001/api/v1/namespaces/backstage/services/backstage-backend:http/proxy +--- +apiVersion: v1 +kind: Service +metadata: + name: backstage-backend + namespace: backstage +spec: + selector: + app: backstage + component: backend + ports: + - name: http + port: 80 + targetPort: http