softshipper
softshipper

Reputation: 34099

How to run the command in deployment?

I have the following deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: keycloak
  namespace: dev
  labels:
    app: keycloak
spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      imagePullSecrets:
        - name: regcred
      containers:
      - name: keycloak
        image: "hub.svc.databaker.io/service/keycloak:0.1.8"
        imagePullPolicy: "IfNotPresent"
        command:
        - "-Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir -Dkeycloak.migration.strategy=OVERWRITE_EXISTING"  

And it can not be deployed. The error message is:

CrashLoopBackOff: back-off 5m0s restarting failed container=keycloak pod=keycloak-86c677456b-tqk6w_dev(6fb23dcc-9fe8-42fb-98d0-619a93f74da1)  

I guess because of the command.

I would like to run a command analog to docker:

keycloak:
    networks:
      - auth
    image: hub.svc.databaker.io/service/keycloak:0.1.7
    container_name: keycloak
    command:
     - "-Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir -Dkeycloak.migration.strategy=OVERWRITE_EXISTING"

How to run a command in K8S deployment?

Update

I have changed the deployment to:

spec:
  replicas: 1
  selector:
    matchLabels:
      app: keycloak
  template:
    metadata:
      labels:
        app: keycloak
    spec:
      imagePullSecrets:
        - name: regcred
      containers:
      - name: keycloak
        image: "hub.svc.databaker.io/service/keycloak:0.1.8"
        imagePullPolicy: "IfNotPresent"
        args:
         - "-Dkeycloak.migration.action=import"
         - "-Dkeycloak.migration.provider=dir"
         - "-Dkeycloak.profile.feature.upload_scripts=enabled"
         - "-Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir"      
         - "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING"

and receive the error:

RunContainerError: failed to start container "012966e22a00e23a7d1f2d5a12e19f6aa9fcb390293f806e840bc007a733c1b0": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"-Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir -Dkeycloak.migration.strategy=OVERWRITE_EXISTING\": stat -Dkeycloak.migration.action=import -Dkeycloak.migration.provider=dir -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir -Dkeycloak.migration.strategy=OVERWRITE_EXISTING: no such file or directory": unknown

Upvotes: 0

Views: 676

Answers (1)

abinet
abinet

Reputation: 2808

If your container has an entrypoint already you can provide the arguments only. This can be done with args. To define or override the entrypoint use command.

keycloak:
    networks:
      - auth
    image: hub.svc.databaker.io/service/keycloak:0.1.7
    container_name: keycloak
    command: ["./standalone.sh"]
    args:
     - "-Dkeycloak.migration.action=import"
     - "-Dkeycloak.migration.provider=dir"
     - "-Dkeycloak.profile.feature.upload_scripts=enabled"
     - "-Dkeycloak.migration.dir=/opt/jboss/keycloak/import-dir"      
     - "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING"

Upvotes: 3

Related Questions