Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use basic authentication in a HTTP liveness probe in Kubernetes?

Tags:

kubernetes

I have a Docker container that expose a health check that is protected by a basic authentication. I've read the documentation on liveness probes here but I cannot find any details of how to specify basic auth credentials. Is this not supported by Kubernetes? Are there any workarounds?

like image 624
Johan Avatar asked Nov 02 '15 19:11

Johan


People also ask

What is the functionality of liveness probe in Kubernetes?

The kubelet uses liveness probes to know when to restart a container. For example, liveness probes could catch a deadlock, where an application is running, but unable to make progress. Restarting a container in such a state can help to make the application more available despite bugs.


Video Answer


1 Answers

It is now possible to add headers for liveness probes:

livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
    httpHeaders:
      - name: Authorization
        value: Basic aGE6aGE=

It may be worth noting that:

if the browser uses Aladdin as the username and OpenSesame as the password, then the field's value is the base64-encoding of Aladdin:OpenSesame, or QWxhZGRpbjpPcGVuU2VzYW1l. Then the Authorization header will appear as:

Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l

Source: https://en.wikipedia.org/wiki/Basic_access_authentication

You can use the command base64 in your shell to create this string:

echo -n "Aladdin:OpenSesame" | base64
like image 196
DDS Avatar answered Oct 23 '22 22:10

DDS