/kubernetes-hello-secret

Example containerized Go web server application

Primary LanguageGoGNU General Public License v3.0GPL-3.0

kubernetes-hello-secret 🕵🏻‍♂️

Slight variation of the sample Hello App.

It creates an hello-app deployment in the hello namespace that consume a hello-secrets secret value mounting it on the SECRET environment variable.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-app
  namespace: hello
  ...
spec:
    ...
    spec:
      containers:
      - name: hello-app
        image: ghcr.io/nikever/kubernetes-hello-secret:latest
        ...
        env:
        - name: SECRET
          valueFrom:
            secretKeyRef:
              name: hello-secret
              key: secret

The ghcr.io/nikever/kubernetes-hello-secret:latest contains a containerized Go web server application that responds to all HTTP requests with the value of the SECRET environment variable.

Hello, secret!
Secret: <VALUE>

The source code is available at /docker/main.go

Deploy Hello Secret App

Prerequisites

  • kustomize >= 3.6

Deployment

  1. Deploy the secret:
kubectl create secret generic -n hello hello-secret --from-literal=secret=1234
  1. Build the application manifests and apply:
cd manifest
kustomize build manifests/ | kubectl apply -f -
  1. Verify that the ingress controller is directing traffic:
curl -H "Host: hello-secret.info" $(minikube ip)

Output:

Hello, secret!
Secret: 1234

References