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

Time:11-26

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:

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?

CodePudding user response:

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.

  • Related