RohanNagar / rohannagar.github.io

A personal landing page
https://www.rohannagar.com
MIT License
0 stars 0 forks source link

Running Dropwizard Applications on Kubernetes · Rohan Nagar #4

Open utterances-bot opened 5 years ago

utterances-bot commented 5 years ago

Running Dropwizard Applications on Kubernetes · Rohan Nagar

https://rohannagar.github.io/2018-04-11/dropwizard-on-kubernetes

liufuyang commented 5 years ago

Hi there, thanks for the post, it is helpful.

I've got a question here: If I have some secretes (passwords and so on) which is also defined in the dropwizard config.yaml file, is there a way to somehow inject those secrets into the configmaps?

RohanNagar commented 5 years ago

@liufuyang thank you for reading!

The most straightforward way if you have secrets in your config.yaml file would be to put the config.yaml file in the Kubernetes cluster as a Kubernetes Secret.

You can create a secret from the file using kubectl, then mount the secret into the Pod rather than mounting the configmap.

RohanNagar commented 3 years ago

Someone recently reached out to me via email regarding this post with a question about running multiple commands on container startup within Kubernetes. To achieve that, update the Deployment.spec section of the application-deployment.yaml file to the following:

spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: application
    spec:
      containers:
        - name: application
          image: yourname/application:test
          imagePullPolicy: Always
          command: ["/bin/sh", "-c"]
          args: ["firstcommand -arg1 && secondcommand -arg1 -arg2 && java -jar /application.jar server /home/config/config.yaml"]
          ports:
            - containerPort: 80
            - containerPort: 81
          volumeMounts:
            - name: config-volume
              mountPath: /home/config
          livenessProbe:
            httpGet:
              path: /healthcheck
              port: 81
            initialDelaySeconds: 10
            timeoutSeconds: 1
          readinessProbe:
            httpGet:
              path: /healthcheck
              port: 81
            initialDelaySeconds: 10
            timeoutSeconds: 1
      volumes:
        - name: config-volume
          configMap:
            name: application-config

Essentially, you will override the command that is run on container startup and then use sh -c to run the set of commands. Separate commands with && so that they are run one after another, and make sure to end with the command to start up your Dropwizard application.