Project structure: microservices/*/k8s.yaml

Note

This file is rendered as a template. Refer to Conf files templating for more details.

A microservice on Hasura is defined as a Kubernetes Deployment and a corresponding Kubernetes Service. Both of these objects are saved in a single file, k8s.yaml as a Kubernetes List object.

Whenever you git push or use hasura ms apply, this file is read and the objects are created on the cluster. You can edit this file to add secrets and other environment variables for the microservice.

Docker image

The docker image to be used by the microservice is given as image: key in k8s.yaml. You can change it, commit and push to get the new image deployed.

For microservices with continuous integration enabled, i.e. their name appears in ci.yaml, the image key is ignored. The image is built on the cluster using Dockerfile and the image is updated automatically, post git push.

Secrets

Check out this page for more info on using secrets.

Environment variables

Check out this page for more info on passing ENV variables to a microservice.

Ports

The port on which the microservice is listening at should be denoted in k8s.yaml. A port and a target port is mentioned in the ports section along with the protocol used and a name. Multiple ports can also be defined in this manner. A service section in k8s.yaml for a microservice with port 8080 on the microservice mapped to port 80 would look like the following:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: app
    hasuraService: custom
  name: app
  namespace: '{{ cluster.metadata.namespaces.user }}'
spec:
  ports:
  - name: http-port
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: app
  type: ClusterIP
status:
  loadBalancer: {}

Note

If another microservice wants to contact this one, it would do so by making an API call to http://app.default:80

You can find sample file for a python-flask microservice at hasura/hello-python-flask/microservices/app/k8s.yaml.