Kubernetes: How can I use the Status API?


#1

I’d like to use the status API to report the status of my app while it is starting up, as described here https://help.replicated.com/api/integration-api/status-api/. possibly even using this container image https://github.com/codeclimate/update-replicated-status.

Are there any docs or examples on doing this? How can I tell my pods where the $REPLICATED_INTEGRATIONAPI is hosted?


#2

I’m afraid there aren’t any official examples of how to use this API, but the CodeClimate repo and docker image you linked has a nearly complete usage example as part of run.sh and reproduced below:

#!/bin/sh
set -e

message=$(printf '%s ' "[email protected]")
data=$(jq --null-input --arg message "$message" '{message: $message}')

curl \
  --insecure \
  --request PUT "$REPLICATED_INTEGRATIONAPI/status/v1/startup" \
  --header "Content-Type: application/json" \
  --data "$data"

The REPLICATED_INTEGRATIONAPI environment variable is supplied by Replicated to all containers started by Replicated - there’s nothing you have to do to include it.

The only real thing that this example doesn’t cover is the optional ‘status’ parameter - if status: "error" is included within the json payload, Replicated will abort starting your app and display that message as an error on the dashboard.


#3

Unfortunately, that environment variable is not automatically provided for you on Kubernetes. Here’s an example of how to use the codeclimate/update-replicated-status image to create a kubernetes job that sets your application status:

---
# kind: scheduler-kubernetes

apiVersion: batch/v1
kind: Job
metadata:
  name: replicated-status
spec:
  template:
    spec:
      containers:
      - name: replicated-status
        image: codeclimate/update-replicated-status
        command: ["run.sh", "I'm setting a status!"]
        env:
        - name: REPLICATED_INTEGRATIONAPI
          value: '{{repl PremkitAPIAddress}}'
        resources:
          requests:
            cpu: 100m
            memory: 100Mi

In this case, the PremkitAPIAddress template function provides the address that the Replicated API can be accessed on.

This environment variable is provided on both Swarm and Native, however.