Inject vault secret into k8s config map - kubernetes

For ArgoCD configuration I would like to pass vault secrets into ConfigMap.
My config map template:
{{- if .Values.server.configEnabled }}
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-cm
labels:
{{- include "argo-cd.labels" (dict "context" . "component" .Values.server.name "name" "cm") | nindent 4 }}
{{- if .Values.server.configAnnotations }}
annotations:
{{- range $key, $value := .Values.server.configAnnotations }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
data: {{- include "argo-cd.config" $ | nindent 4 }}
{{- end }}
and values part:
server:
podAnnotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/auth-path: "auth/gke"
vault.hashicorp.com/role: "default-role"
config:
oidc.config: |
name: Google
issuer: https://accounts.google.com
clientID: |
{{- with secret "secret-gke/data/argocd/argocd-server/client" -}}
{{ .Data.data.clientID }}
{{- end -}}
clientSecret: |
{{- with secret "secret-gke/data/argocd/argocd-server/client" -}}
{{ .Data.data.clientSecret }}
{{- end -}}
podAnnotations allow to inject secrets into Pod and configAnnotations do not solve the issue, so how to inject secrets into ConfigMap?

Related

nil pointer evaluating interface {}.name when deploy helm chart

I am new to helm and kubernetes, so I maybe missed something.
I have created a Helm Chart to deploy MISP. Unfortunately, I am now getting the following error.
Error: INSTALLATION FAILED: template: misp/templates/serviceaccount.yaml:4:11: executing "misp/templates/serviceaccount.yaml" at <include "misp.fullname" .>: error calling include: template: misp/templates/_helpers.tpl:7:40: executing "misp.fullname" at <.Values.misp.name>: nil pointer evaluating interface {}.name
My helpers.tpl looks like this:
{{/*
This is a helper template file that defines the misp.name variable.
*/}}
{{- define "misp.fullname" -}}
{{- printf "%s-%s" .Release.Name .Values.misp.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- define "misp.name" -}}
misp
{{- end -}}
{{- define "misp-chart.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "misp-chart.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "misp-chart.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "misp-chart.labels" -}}
helm.sh/chart: {{ include "misp-chart.chart" . }}
{{ include "misp-chart.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "misp-chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "misp-chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "misp-chart.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "misp-chart.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
and my templates/serviceaccount.yaml like this:
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "misp.fullname" . }}
labels:
app: {{ include "misp.name" . }}
chart: {{ include "misp.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
And here my values.yaml
# Default values for misp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
replicaCount: 1
image:
repository: coolacid/misp
tag: latest
pullPolicy: IfNotPresent
service:
type: ClusterIP
port: 8080
ingress:
enabled: false
# Used to create an Ingress record.
hosts:
- misp.example.com
annotations:
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
tls:
# Secrets must be manually created in the namespace.
- secretName: misp-tls
hosts:
- misp.example.com
database:
mariadb:
enabled: true
image:
repository: bitnami/mariadb
tag: 10.3.23-debian-10-r44
pullPolicy: IfNotPresent
rootUser:
password: password
# databaseName: misp
# user: misp
# password: misp
redis:
enabled: true
image:
repository: bitnami/redis
tag: 6.0.6-debian-10-r0
pullPolicy: IfNotPresent
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
Thank you for your help
try to regenerate the files

Helm - How to add a label block through values.yaml

I have simple helm chart. I have a labels: block that I need to refer in a Deployment
Here's my values.yaml
labels:
app: test-app
group: test-group
provider: test-provider
And in the templates/deployment.yaml I need to add the above whole labels block. So I did;
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ include "accountmasterdata.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{ .Values.labels | nindent 4 }}
{{- include "accountmasterdata.labels" . | nindent 4 }}
But I get the following error
wrong type for value; expected string; got map[string]interface {}
Can someone help me with two things:
How can I solve this issue
And in the line where it says {{- include "accountmasterdata.labels" . | nindent 4 }} , where I can see the accountmasterdata.labels values? And how to override those?
Thank you!
Iterating over a mapping is covered in the "Variables" documentation:
For data structures that have both a key and a value, we can use range to get both. For example, we can loop through .Values.favorite like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-configmap
data:
myvalue: "Hello World"
{{- range $key, $val := .Values.favorite }}
{{ $key }}: {{ $val | quote }}
{{- end }}
So in your template, you would handle the value of .Values.labels like this:
labels:
{{- range $name, $value := .Values.labels }}
{{ $name | quote }}: {{ $value | quote }}
{{- end -}}
And in the line where it says {{- include "accountmasterdata.labels" . | nindent 4 }} , where I can see the accountmasterdata.labels values? And how to override those?
Is this a template you are writing? If so, where have you defined these values? Presumably in your templates/ directory there exists a file that includes something like:
{{- define "accountmasterdata.labels" -}}
...
{{- end -}}
The contents of that block are what will get inserted at the point of reference.
Lastly, in your template you have:
namespace: {{ .Values.namespace }}
But you probably want to use .Release.Namespace instead:
namespace: {{ .Release.Namespace | quote }}
With the above changes in place, I end up with:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ include "accountmasterdata.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- range $name, $value := .Values.labels }}
{{ $name | quote }}: {{ $value | quote }}
{{- end -}}
{{- include "accountmasterdata.labels" . | nindent 4 }}

Kubernetes helm "Ingress.spec.rules[0].http.paths" got "map", expected "array"

So I have been trying to fix some charts we inherited and all the others went fine except this 1 which is giving me a headache.
I understand what thew error is telling me
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Ingress.spec.rules[0].http.paths): invalid type for io.k8s.api.networking.v1.HTTPIngressRuleValue.paths: got "map", expected "array" but I can't find where this map appears in the spec below. I see the paths being in list format.
Does anyone have any idea where exactly the problem is?
Azure AKS 1.24.0
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "something.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $ingressPath := .Values.ingress.path -}}
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
apiVersion: networking.k8s.io/v1
{{- else if .Capabilities.APIVersions.Has "extensions/v1beta1" }}
apiVersion: extensions/v1beta1
{{- else }}
{{ fail "Unsupported API version"}}
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app.kubernetes.io/name: {{ .Chart.Name }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
app.kubernetes.io/component: {{ .Values.component }}
app.kubernetes.io/part-of: {{ .Values.partof }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
{{- with .Values.labels.something}}
{{ toYaml . }}
{{- end }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ . }}
{{- end }}
http:
paths:
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
backend:
service:
name: {{ default $fullName .Values.service.name }}
port:
number: {{ .Values.service.port }}
{{- else if .Capabilities.APIVersions.Has "extensions/v1beta1" }}
backend:
serviceName: {{ default $fullName .Values.service.name }}
servicePort: {{ .Values.service.port }}
{{- end }}
{{- end }}
EDIT 1
Doing a helm lint . with the same flags that the helm upgrade --install would do, throws no errors
You have:
paths:
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
...
You're missing the actual path:
paths:
- path: /
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
pathType: Prefix
...

Helm3 template error calling include: template: no template "microservice.labels" associated with template "gotpl"

I have helm 3 template created using helm create microservice command. it has below files.
/Chart.yaml
./values.yaml
./.helmignore
./templates/ingress.yaml
./templates/deployment.yaml
./templates/service.yaml
./templates/serviceaccount.yaml
./templates/hpa.yaml
./templates/NOTES.txt
./templates/_helpers.tpl
./templates/tests/test-connection.yaml
Updated values file based on my application, when I try to install the helm chat its giving below error message.
Error: UPGRADE FAILED: template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
helm.go:75: [debug] template: microservice/templates/ingress.yaml:20:8: executing "microservice/templates/ingress.yaml" at <include "microservice.labels" .>: error calling include: template: no template "microservice.labels" associated with template "gotpl"
Here is the ingress.yaml file.
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "microservice.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "microservice.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
How to I added microservice.labels template?. Do I need to create microservice.labels.tlp file?
Any tips to fix this error.
Thanks
SR
I copied the ingress.yaml file to, chart created older version helm. this value was missing in _helpers.tpl file. Now I copied new version of hellpers.tpl file. deployment works now.

Ingress uses http instead of https

I am using Azure Kubernetes Service to deploy my applications. I deployed application access to it via Ingress. Application must request permissions from another service using https. But in the logs I see this error message
Invalid redirect_uri: "http://test-api.dev.net/signin-oidc"
As if my traffic for application is not using https
ingress.yml
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "test-api.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "test-api.labels" . | nindent 4 }}
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
more_clear_headers Server;
spec:
{{- if .Values.ingress.tls }}
tls:
- hosts:
- {{ .Values.ingress.tls.hosts }}
secretName: {{ .Values.ingress.tls.secretName }}
{{- end }}
rules:
{{- range $key, $value := .Values.ingress.hosts }}
- host: {{ $value | quote }}
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
service.yml
apiVersion: v1
kind: Secret
metadata:
name: {{ include "test-api.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "test-api.name" . }}
helm.sh/chart: {{ include "test-api.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
{{- toYaml .Values.secretVars | nindent 2 }}
Could you help me? Thanks.