Given a Kubernetes pod with a yaml as shown below, are there any way to set up the value of the terminationGracePeriodSeconds according to some global/internal variable of the application being executed.
Otherwise said and more generally, I know that through downward API, data from the infrastructure/kubernetes (IP, host, …) can be exposed to the application. On the other side, are there any method to expose internal application data/variables to the infrastructure i.e. Kubernetes.
You need to run a function like kubectl apply, or kubectl patch, to trigger update of manifest file parameters. so its not just like setting terminationGracePeriodSeconds: $somevar and have it updated every time the variable changes.
If change of this value is once per deployment, you can use template tools like Helm, or Knative.
or you can use operator framework to implement your own operator for this purpose.
This sort of configuration is exactly what tools like Helm are good for. You could configure a Helm chart with a value:
# charts/my-app/values.yaml
# terminationWait specifies the time to wait for a process to exit
# before forcibly killing the container.
terminationWait: 60
And then reference that value in your YAML manifests:
# charts/my-app/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
terminationGracePeriodSeconds: {{ .Values.terminationWait }}
More generally it uses the Go text/template language, with a large set of extensions, so it's possible to do almost anything with this setup, though it's easiest and clearest to stick with simple value substitution like what's shown here.