Search code examples
kubernetesminikubehashicorp-vaultvapor

How to run a hello word Vapor app in minikube? How to set up hashicorps in Kubernetes?


I am new to Kubernetes. Did this so far:

vapor new hello -n
open Package.swift
ls
cd hello
open Package.swift
swift run
docker compose build
docker image ls
docker compose up app
minikube kubectl -- apply -f docker-compose.yml
minikube kubectl -- apply -f docker-compose.yml --validate=false

based on this tutorial: https://docs.vapor.codes/deploy/docker/ and video: https://www.youtube.com/watch?v=qFhzu7LolUU

but I got following error in two last line:

kukodajanos@Kukodas-MacBook-Pro hello % minikube kubectl -- apply -f docker-compose.yml 
error: error validating "docker-compose.yml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false

Someone said, I need to set up a deployment file?! https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment

My second goal is I would have hashicorp install in the cluster to be able to return short living secrets. I.e. secret for connection to a database which is used by the cluster. Would you give a step by step tutorial how can I do it?

// docker-compose.yml

x-shared_environment: &shared_environment
  LOG_LEVEL: ${LOG_LEVEL:-debug}
  
services:
  app:
    image: hello:latest
    build:
      context: .
    environment:
      <<: *shared_environment
    ports:
      - '8080:8080'
    # user: '0' # uncomment to run as root for testing purposes even though Dockerfile defines 'vapor' user.
    command: ["serve", "--env", "production", "--hostname", "0.0.0.0", "--port", "8080"]

Solution

  • So in simple words when you try to apply a file in Kubernetes you will need to follow a basic template which make Kubernetes understand what kind of resource you are trying to create. One of this is apiVersion so please try to follow the below deployment I was not able to find the docker image for the application here you will need to just add the docker image and port number where the application runs.

    If you have the Dockerfile you can build and push the image to container registry and then use the image tag to pull the same image.

    Reference : How to write Kubernetes manifest file

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: vaporapp
      labels:
        app: vaporapp
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: vaporapp
      template:
        metadata:
          labels:
            app: vaporapp
        spec:
          containers:
          - name: vaporapp
            image: signalsciences/example-helloworld:latest
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 8000
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: vapor-service
      labels:
        app: vaporapp
    spec:
      ports:
      - name: http
        port: 8000
        targetPort: 8000
      selector:
        app: vaporapp
      type: LoadBalancer