Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Kubernetes pod doesn't serve a website when commands are used inside pod definition

The pod is defined as:

apiVersion: v1
kind: Pod
metadata:
  name: playground-pod
  labels:
    name: playground-pod
    app: playground-app
spec:
  containers:
  - name: playground
    image: localhost:5000/playground:1.8
    ports:
    - containerPort: 80
#    command:
#    - sh
#    - -c
#    args:
#    - cat /usr/share/nginx/html/env.js && echo $REACT_APP_ENV_VARIABLE && echo $REACT_APP_ENV_VARIABLE_TWO
    env:
    - name: REACT_APP_ENV_VARIABLE
      value: "Variable from Kube!"
    - name: REACT_APP_ENV_VARIABLE_TWO
      value: "192.168.0.120"

It serves a simple website when the commented lines remain commented, but when they are uncommented to log some data, the website doesn’t appear at all.

The pod itself is running, it logs the data correctly, i.e. the variables get set up:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

kubectl logs playground-pod
window.env = {
  "REACT_APP_ENV_VARIABLE": "__ev1__",
  "REACT_APP_ENV_VARIABLE_TWO": "__ev2__"
};Variable from Kube!
192.168.0.120

How to enable serving of the website, having at the same time possibility to manipulate data inside the created container?

>Solution :

The Dockerimage has usually a default command that start the process inside. Its often the last line in the Dockerfile used to create the image.

the command option in the pod yaml overwrites that command to start the server in the Dockerfile. You could look that up and append that command to your command in the yaml file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading