There are cases when you want to restart a specific container instead of deleting the pod and letting Kubernetes recreate it.
i am having one pod running apache container. i did editing in apache config file. for SSL certificate virtual host port changes etc.
now i want to restart apache2 service but without recreating pod.
i tried inside pod with
service apache2 restart
but it also recreate pod and configuration also change again.
check this
You can also create a new dockerfile for override the apache dockerfile and change de CMD line, but it's more complicated
This is not how it supposed to work.
You should not change anything inside the POD
. If your POD
dies or crushes, Kubernetes should just start a new one and everything should work. Also keep in mind that you cannot scale the POD
that had configuration altered.
Please check the Kubernetes docs Configure a Pod to Use a ConfigMap
You can use ConfigMap
to create configuration file.
ConfigMaps allow you to decouple configuration artifacts from image content to keep containerized applications portable. This page provides a series of usage examples demonstrating how to create ConfigMaps and configure Pods using data stored in ConfigMaps.
ConfigMap
can be created and read a content of a file :
$ kubectl create configmap config_data --from-file=config_data.txt
or it can be declared in .yml
config_map:
data:
db_name=colors_db
table_name=purple
name: config_data
version: v1
Also this might be done by creating a secret
or secret
can be declared:
secret:
data:
username: my-username
password: my-password
name: secret_data
version: v1
I recommend reading Kubernetes recipe: store nginx config with ConfigMap and reverse-proxy requests from your domain to your Github page.
There are also other options like mounting path with needed configuration on new POD
. I advice you to check Configure a Pod to Use a PersistentVolume for Storage