Is it possible to set the working directory when launching a container with Kubernetes ?
Environment Variables and Kubernetes There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external configuration file, using variables, or a secrets file.
Once you created the pod, kubernetes makes some properties immutable. These are mostly the options which can change pods stability, for example this. You can get the manifest using kubectl get pod $PODNAME -o yaml --export . Then edit this manifest and change the restartPolicy field to Never and redeploy it.
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.
Yes, through the workingDir
field of the container spec. Here's an example replication controller with an nginx container that has workingDir
set to /workdir
:
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx
spec:
replicas: 1
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: mynginximage
workingDir: /workdir
It should be also possible to set the working directory using env and command attributes. Below is an example:
apiVersion: v1 kind: Pod metadata: name: print-greeting spec: containers: - name: env-print-demo image: bash env: - name: GREETING value: "Warm greetings to" - name: HONORIFIC value: "The Most Honorable" - name: NAME value: "Kubernetes" command: ["echo"] args: ["$(GREETING) $(HONORIFIC) $(NAME)"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With