In this example, we will deploy an app called my-app
and it will read the application configuration from a ConfigMap.
Change into the lab directory:
cd /workspaces/kubernetes-fundamentals-for-devs/01_configmaps
INGRESS_IP environment variable is supposed to be set during the setup. You can always set it this way:
export INGRESS_IP=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[].ip}')
Apply the manifests:
kubectl apply -f k8s/
curl http://${INGRESS_IP}/my-app
# output:
# <!DOCTYPE html><htlml><body>Message: Message from ConfigMap<br>Pod Name: <br>Pod IP: <br>Live: true<br>Ready: true<br></body></htlml>
If you want to reach it via browser, you first need to port-forward ingress-nginx-controller service:
kubectl port-forward svc/ingress-nginx-controller -n ingress-nginx 80
Then, reach via below URLs:
echo "https://${CODESPACE_NAME}-80.app.github.dev/my-app"
Note that the the message is taken from the ConfigMap and not from the containers default configuration file for the application.
Change the message of the ConfigMap k8s/configmap.yaml
data:
app.conf: |-
message = Some different message
Apply the change in the ConfigMap.
kubectl apply -f k8s/configmap.yaml
or run the below command:
kubectl patch cm my-configmap -p '{"data": {"app.conf": "message = Some different message"}}'
Note: ConfigMap changes will not be reflected automatically. You need to restart the pod. (In this case, recreate/replace). You can get into tricky situations eg on deploying stuff via Helm Charts.
# restart the pod
kubectl replace -f k8s/pod.yaml --force
# verify that the message is updated
curl http://${INGRESS_IP}/my-app
If you want to reach it via browser, you first need to port-forward ingress-nginx-controller service:
kubectl port-forward svc/ingress-nginx-controller -n ingress-nginx 80
Then, reach via below URLs:
echo "https://${CODESPACE_NAME}-80.app.github.dev/my-app"
There are some automated ways to restart your applications after ConfigMap/Secret changes. For example:
- Kyverno Policy: Restart Deployment on a Secret Change
- Helm: Automatically Roll Deployments
kubectl delete -f k8s/