Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add external-service helm chart #6

Merged
merged 2 commits into from
Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/job_conformity-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
version: v3.7.2

- name: Render helm templates
run: helm template test ${{ matrix.charts }} --output-dir build
run: helm template test ${{ matrix.charts }} --kube-version ${{ matrix.k8s }} --output-dir build

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
Expand Down
23 changes: 23 additions & 0 deletions charts/external-service/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
15 changes: 15 additions & 0 deletions charts/external-service/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
name: external-service
description: This Helm Chart allows services that operate outside the Kubernetes cluster to be accessible via the ingress controller.
type: application
version: 1.0.0
kubeVersion: ^1.15.0
appVersion: v1.0.0
sources:
- https://github.com/philippwaller/helm-charts
keywords:
- service
- external-service
maintainers:
- name: philippwaller
url: https://git.philippwaller.com
56 changes: 56 additions & 0 deletions charts/external-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# External Service

This Helm Chart allows services that operate outside the Kubernetes cluster to be accessible via the ingress controller.

## TL;DR

```console
$ helm install my-service philippwaller/external-service
```

## Introduction

This chart deploys an Endpoint, Service and Ingress configuration on a [Kubernetes](https://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager.


## Prerequisites

- Kubernetes 1.15+
- Helm 3.1+


## Parameters

### Common parameters

| Name | Description | Value |
| ------------------ | -------------------------------------------------- | ----- |
| `nameOverride` | String to partially override common.names.fullname | `""` |
| `fullnameOverride` | String to fully override common.names.fullname | `""` |


### Service Configuration

| Name | Description | Value |
| -------------------- | --------------------------------------- | ----------- |
| `service.ip` | IP addresses of the external service | `10.0.0.1` |
| `service.targetPort` | Port of the external service | `80` |
| `service.protocol` | Protocol of the external service | `TCP` |
| `service.name` | Name of the external port | `http` |
| `service.port` | Port of the internal Kubernetes service | `80` |
| `service.type` | Service type | `ClusterIP` |


### Ingress Configuration

| Name | Description | Value |
| --------------------- | --------------------------------------------------------------------------- | ------ |
| `ingress.enabled` | Enable ingress record generation | `true` |
| `ingress.className` | IngressClass that will be be used to implement the Ingress | `""` |
| `ingress.annotations` | Additional annotations for the Ingress resource. | `{}` |
| `ingress.hosts` | An array with ingress host objects, under which service should be reachable | `{}` |
| `ingress.tls` | An array of TLS configurations | `{}` |


## Support this project
If this project was useful to you in some form, I would be glad to have your support by starring ⭐️ this repository.
42 changes: 42 additions & 0 deletions charts/external-service/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "external-service.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 "external-service.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 "external-service.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "external-service.labels" -}}
helm.sh/chart: {{ include "external-service.chart" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/external-service/templates/endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Endpoints
metadata:
name: {{ include "external-service.fullname" . }}
labels:
{{- include "external-service.labels" . | nindent 4 }}
subsets:
- addresses:
- ip: {{ .Values.service.ip }}
ports:
- name: {{ .Values.service.name }}
port: {{ .Values.service.targetPort }}
protocol: {{ .Values.service.protocol }}
61 changes: 61 additions & 0 deletions charts/external-service/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "external-service.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 "external-service.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 }}
13 changes: 13 additions & 0 deletions charts/external-service/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "external-service.fullname" . }}
labels:
{{- include "external-service.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.service.targetPort }}
protocol: {{ .Values.service.protocol }}
name: {{ .Values.service.name }}
56 changes: 56 additions & 0 deletions charts/external-service/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Default values for external-service.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

## @section Common parameters
##

## @param nameOverride String to partially override common.names.fullname
nameOverride: ""

## @param fullnameOverride String to fully override common.names.fullname
fullnameOverride: ""

## @section Service Configuration
##

service:
## @param service.ip IP addresses of the external service
ip: 10.0.0.1
## @param service.targetPort Port of the external service
targetPort: 80
## @param service.protocol Protocol of the external service
protocol: TCP
## @param service.name Name of the external port
name: http
## @param service.port Port of the internal Kubernetes service
port: 80
## @param service.type Service type
type: ClusterIP

## @section Ingress Configuration
## ref: https://kubernetes.io/docs/user-guide/ingress/
##

ingress:
## @param ingress.enabled Enable ingress record generation
enabled: true
## @param ingress.className IngressClass that will be be used to implement the Ingress
className: ""

## @param ingress.annotations [object] Additional annotations for the Ingress resource.
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"

## @param ingress.hosts [object] An array with ingress host objects, under which service should be reachable
hosts:
- host: myservice.example.com
paths:
- path: /
pathType: ImplementationSpecific
## @param ingress.tls [object] An array of TLS configurations
tls: []
# - secretName: my-service-example-com-tls
# hosts:
# - myservice.example.com