0

I have a solr container that needs to be started with a parameter, either master or slave. I'm trying to put the env var into the container so that the init script can read it, and start as a master or slave.

        env:
          - name: ROLE
            value: "master"

The container starts up, and when I shell into the container, I can see the ROLE var has been set but it appears as if the init script didn't pick it up.

Does the env var get set before or after init scripts run? If so, how do I get this var injected so that the script can have it available? I'd rather not do a ConfigMap or Secret just for this small var.

This container has been converted from EC2 to a container image by Migrate for Anthos and is running in an Anthos cluster.

Dockerfile example, reproducable

# Please refer to the documentation:
# https://cloud.google.com/migrate/anthos/docs/dockerfile-reference

FROM anthos-migrate.gcr.io/v2k-run-embedded:v1.8.1 as migrate-for-anthos-runtime

# Image containing data captured from the source VM
FROM mi5key/testing:v0.0.4

COPY --chown=root:root env-vars /etc/rc.d/init.d/env-vars
RUN /sbin/chkconfig env-vars on

COPY --from=migrate-for-anthos-runtime / /

ADD blocklist.yaml /.m4a/blocklist.yaml

ADD logs.yaml /code/config/logs/logsArtifact.yaml

# Migrate for Anthos image includes entrypoint
ENTRYPOINT [ "/.v2k.go" ]

deployment_spec.yaml

# Stateless application specification
# The Deployment creates a single replicated Pod, indicated by the 'replicas' field
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: env-vars-test
    migrate-for-anthos-optimization: "true"
    migrate-for-anthos-version: v1.8.1
  name: env-vars-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: env-vars-test
      migrate-for-anthos-optimization: "true"
      migrate-for-anthos-version: v1.8.1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: env-vars-test
        migrate-for-anthos-optimization: "true"
        migrate-for-anthos-version: v1.8.1
    spec:
      containers:
      - image: docker.io/mi5key/testing:v0.0.4
        imagePullPolicy: IfNotPresent
        name: env-vars-test
        readinessProbe:
          exec:
            command:
            - /code/ready.sh
        resources:
          limits:
            memory: "1Gi"
            cpu: "1"
        env:
          - name: ROLE
            value: "single"
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /sys/fs/cgroup
          name: cgroups
      volumes:
      - hostPath:
          path: /sys/fs/cgroup
          type: Directory
        name: cgroups
status: {}
  • Containers don't usually run init scripts. Can you provide a [mcve], including for example the image's Dockerfile? – David Maze Sep 30 '21 at 23:04
  • Please edit the question and include details in the question itself; as text and not other formats, directly in the question and not behind a link. – David Maze Oct 01 '21 at 20:17
  • @david-maze ok, edited the question. – Mike Davis Oct 01 '21 at 21:01
  • What's in the `mi5key/testing` image, and the `v2k.go` program? If you're trying to import a VM into Kubernetes (there are a couple of hints at this, including trying to use the host's cgroups directory) then the VM's init system will probably reset the entire environment; a better approach would be to build a custom image, with a Dockerfile checked into source control, that includes the single specific program you want to run. – David Maze Oct 01 '21 at 22:29
  • "This container has been converted from EC2 to a container image by Migrate for Anthos and is running in an Anthos cluster." The testing image is one I created by standing up an EC2 linux instances, ran it through Migrate for Anthos, stored the container in mik5ey/testing. v2k.go is the entry point configured by Migrate for Anthos for the container image. – Mike Davis Oct 01 '21 at 23:55

0 Answers0