Kubernetes / k8s
Get a shell to the running Container running in kubenetes with kubectl
kubectl exec -it shell-demo-id -- /bin/bash
How to map file istead of directory from a configmap with volumenMounts
Mount a file from a configmap
- Once you mount a volume(no matter if it's a configmap or others), it overrides the
mountPathwith the key in the config map as files.
- We then need to specify that we only want one of the keys in the ConfigMap. In this way, the original content in
/appfolders won't be affected.
- This is there the
subPathcomes in. We need to tell the volume mounts to use a subpath from our configmap.
- This now means that the mountPath is actually getting mounted as a single file instead of a directory named:
certificate.service.pfxwith all the keys in the configmap in it.
- Below you can see the yaml for it.
containers: volumeMounts: - name: certificate-config mountPath: /app/certificate.service.pfx subPath: certificate.service.pfx volumes: - name: certificate-config configMap: name: certificate-configmap
Install utils in a running docker image
When working with Docker often is uses a very clean linux distro. I often use microsoft/dotnet - both sdk and runetime ... but they don't come with either "ping" or "wget" commands with can be usefull in debug scenarios.
To install the "ping" command use the following when you have a shell for the running container:
apt-get install iputils-ping
You should now be able to use the ping command. The same goes for "wget" ... just use
apt-get install wget instead.
To clear running containers:
docker rm -f $(docker ps -a -q)
To clear build images
docker rmi -f $(docker images -a -q)
To clear volumes:
docker volume rm $(docker volume ls -q)
This command let you explore a docker image:
docker run --rm -it --entrypoint=/bin/bash name-of-image