Golide
Golide

Reputation: 1009

Service.yaml throws null pointer error when running helm upgrade install

I am trying helm install for a sample application consisting of two microservices. I have created a solution level folder called charts and all subsequent helm specific resources (as per this example (LINK) .

When I execute helm upgrade --install microsvc-poc--release . from C:\Users\username\source\repos\MicroservicePOC\charts\microservice-poc (where values.yml is) I get error :

Error: template: microservicepoc/templates/service.yaml:8:18: executing "microservicepoc/templates/service.yaml" at <.Values.service.type>: nil pointer evaluating interface {}.type

I am not quite sure whats the exact issue that causes this behavior,I have set all possible defaults in values.yaml as below :

payments-app-service:


replicaCount: 3

  image:
    repository: golide/paymentsapi
    pullPolicy: IfNotPresent
    tag: "0.1.0"

  service:
    type: ClusterIP
    port: 80

  ingress:
    enabled: true
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: "/"
    hosts:
      - host: payments-svc.local
        paths: 
        - "/payments-app"

  autoscaling:
    enabled: false

  serviceAccount:
    create: false

products-app-service:
  replicaCount: 3

  image:
    repository: productsapi_productsapi
    pullPolicy: IfNotPresent
    tag: "latest"

  service:
    type: ClusterIP
    port: 80

  ingress:
    enabled: true
    annotations:
      nginx.ingress.kubernetes.io/rewrite-target: "/"
    hosts:
      - host: products-svc.local
        paths: 
        - "/products-app"

  autoscaling:
    enabled: false

  serviceAccount:
    create: false

As a check I have opened service.yaml file and it throws syntax errors which I'm thinking to may be related to why helm install is failing : Missed comma between flow control entries

This error is throwing on lines 6 and 15 for service.yaml file below :

apiVersion: v1
kind: Service
metadata:
  name: {{ include "microservicepoc.fullname" . }}
  labels:
    {{- include "microservicepoc.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "microservicepoc.selectorLabels" . | nindent 4 }}

What am I missing ?

I have tried recreating the chart afresh but when I try helm install I get the exact same error. Moreover service.yaml continues showing same syntax error ( I have not edited anything in service.yaml that would otherwise cause linting issues).

Upvotes: 0

Views: 904

Answers (1)

z.x
z.x

Reputation: 2517

As the error describes, helm can't find the service field in the value.yaml file when rendering the template, and it caused the rendering to fail.

The services in your value.yaml file are located under the payments-app-service field and the products-app-service field. To access them, you need to pass {{ .Values.payments-app-service.service.type }} or {{ .Values.products-app-service.service.type }}

like:

apiVersion: v1
kind: Service
metadata:
  name: {{ include "microservicepoc.fullname" . }}
  labels:
    {{- include "microservicepoc.labels" . | nindent 4 }}
spec:
  type: {{ .Values.products-app-service.service.type }}
  ports:
    - port: {{ .Values.products-app-service.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "microservicepoc.selectorLabels" . | nindent 4 }}

It is recommended that you use helm better by reading the official documentation

helm doc

Upvotes: 1

Related Questions