How to reference other environment variables in a Helm values file? - kubernetes-helm

I have a Helm values with content like following:
envs:
- name: PACT_BROKER_DATABASE_NAME
value: $POSTGRES_DBNAME
I want to reference another variable called $POSTGRES_DB_NAME and feed into that PACT_BROKER_DATABASE_NAME. The current value does not work. How do I feed one value to another variable?

I was looking for something to "reference another variable" in the helm variable section, google landed me here, posting as an answer, might help someone else.
I was looking for away to set heap allocation base on pod limit.
env:
- name: MEMORY_LIMIT
valueFrom:
resourceFieldRef:
resource: limits.memory
- name: NODE_OPTIONS
value: "--max-old-space-size=$(MEMORY_LIMIT)"
so I just need $(MEMORY_LIMIT)", so $POSTGRES_DBNAME this should be define in the same pod/container env.

Related

helmfile best practices with multiple customers

We would like to have some recommendations, since we want to integrate helmfile in our deployment process...
Our infrastructure has following details:
we have many customers
all customers have the same installed services
(each customer get's it's own services, no sharing between customers)
credentials are different for each customer
we prefer a seperate
deployment process (we dont want to upgrade all customers at the same
time)
all customer-config data is seperated into seperate config
files, like:
config/customer1.yaml
config/customer2.yaml
config/customer3.yaml
So I'm wondering, if we should use "Environment" with the customer name, to upgrade it.. or would you recommend another variable?
And do you think it's better to create multiple helmfiles for this process, or just one?
Thank you!
do you think it's better to create multiple helmfiles for this process, or just one?
Using one helmfile for multiple environemnts is quite practical and it saves you writing multiple helmfiles.
we should use "Environment" with the customer name?
For a similar setup (deploying to multiple environements with different values and configurations), I have in Helmfile:
- name: my-app
namespace: "{{ .Namespace }}"
chart: k4r-distance-matrix-api
values:
- my-app/values.yaml ## here go the common values if any exists
- my-app/values.{{ .Environment.Name }}.yaml ## here goes the environment specific values
In the deploy step in my CI I have:
.deploy:
stage: deploy
variables:
ENVIRONMENT: ""
CONTEXT: ""
NAMESPACE: ""
before_script:
- kubectl config use-context $CONTEXT
script:
- helmfile -e "$ENVIRONMENT" --namespace "$NAMESPACE" sync

Max size of Environment variables in kubernetes

What is the max size allowed for Environment variable (pod->container->Env) in kubernetes, assuming base ubuntu containers? I am unable to find the relevant documentation. Question might seem stupid, but, I do need the info to make my design robust.
So at bare minimum there is some 1,048,576 byte limitation imposed:
The ConfigMap "too-big" is invalid: []: Too long: must have at most 1048576 characters
which I generated as:
cat > too-big.yml<<FOO
apiVersion: v1
kind: ConfigMap
metadata:
name: too-big
data:
kaboom.txt: |
$(python -c 'print("x" * 1024 * 1024)')
FOO
And when I try that same stunt with a Pod, I'm met with a very similar outcome:
containers:
- image: ubuntu:18.10
env:
- name: TOO_BIG
value: |
$(python -c the same print)
standard_init_linux.go:178: exec user process caused "argument list too long"
So I would guess it's somewhere in between those two numbers: 0 and 1048576
That said, as the practically duplicate question answered, you are very, very likely solving the wrong problem. The very fact that you have to come to a community site to ask such a question means you are brining risk to your project that it will work one way on Linux, another way on docker, another way on kubernetes, and a different way on macOS.

Kubernetes - set env var using the value of one of the auto generated service env vars

Kubernetes automatically generates several environment variables for you, like SERVICE1_SERVICE_HOST and SERVICE1_SERVICE_PORT. I would like to use the value of these variables to set my own variables in the deployment.yml, like below:
env:
- name: MY_NEW_VAR
value: ${SERVICE1_SERVICE_HOST}
For some reason Kubernetes isn't able to resolve this. When I go inside the container it turns out it has been assigned as a literal string, giving me MY_NEW_VAR = ${SERVICE1_SERVICE_HOST}.
Is there a way to assign the value of ${SERVICE1_SERVICE_HOST} instead?
The syntax is $(SERVICE1_SERVICE_HOST), as one can see in the fine manual

Google Cloud Compute, using environment variables

I have found lots of information on how to use environment variables in Google App Engine projects.
However I am yet to find some best practice on what to do with environment variables on compute engine.
Is it possible to use Google Cloud Deployment Manager to achieve this? My main goal is to simplify deployment between prod/stag/dev.
Right now I am moving towards using dotenv files.
Stack is webpack 4, express, node 10, vuejs 2.
For Compute Engine instances I'd suggest to use custom metadata. You can find detailed documentation about this here. From within your instance, you can access your custom metadata by performing an empty request to the instance().get method, for example:
GET https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances/example-instance
Now, to set your custom metadata, you can indeed use the Google Cloud Deployment Manager. As per the doc here, you just need to add the metadata property and the relevant metadata keys and values for your VM resource, for example:
resources:
- name: my-first-vm-template
type: compute.v1.instance
properties:
zone: us-central1-a
machineType:
...[snip]...
metadata:
items:
- key: custom-key
value: "custom-value"

How to pass kubernetes pod instance id to within the pod upon start up?

So I'm researching how to use Kubernetes for my case. I installed it and played a bit.
The question is when the replication controller starts couple of replicas they have something like an id in their name:
How unique is this id? Is it uniqueness for the lifetime of kubernetes? Is it unique across different kubernetes runs (i.e. if I restart kubernetes)?
How to pass this id to the app in the container? Can I specify some kind of template in the yaml so for example the id will be assigned to environment variable or something similar?
Alternatively is there a way for the app in the container to ask for this id?
More explanation of the use case. I have an application that writes some session files inside a directory. I want to guarantee unique for the session ids in the system. This means if one app instance is running on VM1 and another instance on VM2, I want to prepend some kind of identifier to the ids like app-1-dajk4l and app-2-dajk4l, where app is the name of the app and 1, 2 is the instance identifier, which should come from the replication controller because it is dynamic and can not be configured manually. dajk4l is some identifier like the current timestamp or similar.
Thanks.
The ID is guaranteed to be unique at any single point in time, since Kubernetes doesn't allow two pods in the same namespace to have the same name. There aren't any longer-term guarantees though, since they're just generated as a random string of 5 alphanumeric characters. However, given that there are more than 60 million such random strings, conflicts across time are also unlikely in most environments.
Yes, you can pull in the pod's namespace and name as environment variables using what's called the "Downward API", adding a field on the container like
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name