0
votes

I am trying to create new patches using the golang kubernetes sdk and am running into problems removing environmental variables from my containers by using a new deployment that doesn't include them. I've been reading that when doing a new deployment you need to set the new environmental variable to null but how the kubernetes env structs are set up, they use a string field, you cannot set this as null only as "" which just ends up being omitted. Trying to set this as empty string just results in the previous env value persisting and not including it does the same behavior.

Does anyone know the proper way to delete environmental variables from pods using patch and golang?

1
Can you share the code that you have?Arghya Sadhu

1 Answers

1
votes

containers.env has type list. So you can use [] for empty list

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        env: []
        resources: {}
status: {}