Document valid schema for pod's set_spec function and how to set environment variables
See original GitHub issueI am trying without any success to add an environment variable to a charm I’m building for OpenFaaS:
“env” (as per the Kubernetes schema) fails
“envConfig” as seen in the Istio example also fails.
ops.model.ModelError: b'ERROR json: unknown field "env"\n'
ops.model.ModelError: b'ERROR json: unknown field "envConfig"\n'
ops.model.ModelError: b'ERROR json: unknown field "envs"\n'
Attempted Charm:
def _on_config_changed(self, _=None):
pod_spec = self._build_pod_spec()
self.model.pod.set_spec(pod_spec)
self.unit.status = ActiveStatus("OpenFaaS pod ready.")
def _build_pod_spec(self):
spec = {
"containers": [
{
"name": self.app.name,
"imageDetails": {"imagePath": "openfaas/gateway:0.20.2"},
"ports": [{"containerPort": 8080, "protocol": "TCP"}],
"files": [],
"config": {}, # used to store hashes of config file text
"env": [
{"functions_provider_url": "192.168.0.15:8081"},
{"direct_functions": "false"},
{"basic_auth": "false"},
{"faas_prometheus_host": "192.168.0.35"},
{"faas_prometheus_port": "9090"},
]
}
]
}
Kubernetes schema:
containers:
- name: gateway
resources:
requests:
cpu: 50m
memory: 120Mi
image: openfaas/gateway:0.20.2
imagePullPolicy: Always
securityContext:
readOnlyRootFilesystem: true
runAsUser: 10001
livenessProbe:
httpGet:
path: /healthz
port: 8080
timeoutSeconds: 5
readinessProbe:
httpGet:
path: /healthz
port: 8080
timeoutSeconds: 5
env:
- name: read_timeout
value: "65s"
- name: write_timeout
value: "65s"
- name: upstream_timeout
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
Define Environment Variables for a Container - Kubernetes
This page shows how to define environment variables for a container in a Kubernetes Pod. Before you begin. You need to have a...
Read more >How To Handle Environment Variables With Kubernetes?
There are two ways to define environment variables with Kubernetes: by setting them directly in a configuration file, from an external ...
Read more >Use environment variables in solutions - Power Apps
Environment variables allow you to specify which of these different external references should be updated as the application is moved across ...
Read more >pod's name from an environment variables defined in yaml
Kubernetes allows you to set environment variables using the values of other fields in the Pod definition that are only available at the ......
Read more >Using RabbitMQ Cluster Kubernetes Operator
If Pod security policies are not enabled, skip to Create a RabbitMQ Instance below. The Role and RoleBinding should be created before a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unfortunately that code gives the error I shared above, would you be open to giving it a try to see if you can figure out what I’ve missed? https://github.com/alexellis/openfaas-charm-example
There is also a spec here! https://juju.is/docs/charm-writing/kubernetes