Skip to content

Add k8s-daemonset helm-chart - inital cut #134

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions charts/k8s-daemonset/.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/
24 changes: 24 additions & 0 deletions charts/k8s-daemonset/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: k8s-service
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"
61 changes: 61 additions & 0 deletions charts/k8s-daemonset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Kubernetes DaemonSet Helm Chart

This Helm Chart can be used to deploy your application container under a
[DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) resource onto your Kubernetes
cluster. You can use this Helm Chart to run and deploy a long-running container, such as a web service or backend
microservice. The container will be packaged into
[Pods](https://kubernetes.io/docs/concepts/workloads/pods/pod-overview/) that are managed by the `DaemonSet`
controller.

This Helm Chart can be used to deploy the pod under a `DaemonSet` resource onto your Kubernetes cluster.


## How to use this chart?

* See the [root README](/README.adoc) for general instructions on using Gruntwork Helm Charts.
* See the [examples](/examples) folder for example usage.
* See the provided [values.yaml](./values.yaml) file for the required and optional configuration values that you can set
on this chart.

back to [root README](/README.adoc#core-concepts)

## What resources does this Helm Chart deploy?

The following resources will be deployed with this Helm Chart, depending on which configuration values you use:

- `DaemonSet`: The main `DaemonSet` controller that will manage the application container image specified in the
`containerImage` input value.


back to [root README](/README.adoc#core-concepts)


## Useful helm commands:
1. List helm charts

```bash

helm list

NAME NAMESPACE REVISION UPDATED STATUS CHART APP VERSION
my-daemonset-chart default 1 2022-04-27 17:52:38.166977136 +0000 UTC deployed k8s-service-0.1.0 1.16.0

```

2. List daemonsets and pods

```bash

# List Daemonsets
kubectl get daemonset
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
fluentd 1 1 1 1 1 <none> 2m45s

# List pods
kubectl get pods
NAME READY STATUS RESTARTS AGE
fluentd-l9g2s 1/1 Running 0 3m14s
```


back to [root README](/README.adoc#day-to-day-operations)
54 changes: 54 additions & 0 deletions charts/k8s-daemonset/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{{- if .Values.DaemonSet.create }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ .Values.DaemonSet.name }}
namespace: {{ $.Release.Namespace }}
labels:
app: {{ .Values.DaemonSet.name }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
release: {{ .Release.Name }}
spec:
selector:
matchLabels:
app: {{ .Values.DaemonSet.name }}
release: {{ .Release.Name }}
updateStrategy:
{{- if eq .Values.DaemonSet.updateStrategy "RollingUpdate" }}
rollingUpdate:
maxUnavailable: {{ .Values.DaemonSet.maxUnavailable }}
{{- end }}
template:
metadata:
labels:
app: {{ .Values.DaemonSet.name }}
release: {{ .Release.Name }}
spec:
tolerations:
- key: {{ .Values.DaemonSet.tolerationKey }}
operator: {{ .Values.DaemonSet.tolerationOperator }}
effect: {{ .Values.DaemonSet.tolerationEffect }}
containers:
- name: {{ .Values.DaemonSet.name }}
image: {{ .Values.DaemonSet.containerImage }}
{{- if .Values.DaemonSet.volumeMountCreate }}
volumeMounts:
- name: {{ .Values.DaemonSet.volumeName }}
mountPath: {{ .Values.DaemonSet.volumeMountPath }}
{{- if .Values.DaemonSet.extraVolumeMountCreate }}
- name: {{ .Values.DaemonSet.extraVolumeName }}
mountPath: {{ .Values.DaemonSet.extraVolumeMountPath }}
readOnly: true
{{- end }}
volumes:
- name: {{ .Values.DaemonSet.volumeName }}
hostPath:
path: {{ .Values.DaemonSet.volumeMountPath }}
{{- end }}
{{- if .Values.DaemonSet.extraVolumeMountCreate }}
- name: {{ .Values.DaemonSet.extraVolumeName }}
hostPath:
path: {{ .Values.DaemonSet.extraVolumeMountPath }}
{{- end }}
{{- end }}

29 changes: 29 additions & 0 deletions charts/k8s-daemonset/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# DaemonSet is a map that configures the pods to run as daemon on all (or some) Nodes.
# The expected keys of DaemonSet are:
# - name (string) : The name of the DaemonSet.
# - create (bool) : Whether or not to create a DaemonSet with the desired name
# - labels (map) : Labels will add the provided map to the DaemonSet created
# - selectorLabels (map) : Tells the resource to match the pod, according to that label
# - tolerationKey (string) : Toleration Key, Example: node-role.kubernetes.io/master
# - tolerationOperator (string) : Toleration Operator, Example: Exists
# - tolerationEffect (string) : Toleration Key, Example: NoSchedule
# - volumeName (string) : Name of the volumes mount inside container
# - volumeMountPath (string) : Path name to Mount volumes into container
# - updateStrategy (string) : Type of deployment
# - maxUnavailable (number) : Only used when updateStrategy is set to "RollingUpdate"

DaemonSet:
name: "fluentd"
create: true
tolerationKey: "node-role.kubernetes.io/master"
tolerationOperator: "Exists"
tolerationEffect: "NoSchedule"
containerImage: "quay.io/fluentd_elasticsearch/fluentd:v2.5.2"
volumeMountCreate: true
volumeName: "varlog"
volumeMountPath: "/var/log"
updateStrategy: "RollingUpdate"
maxUnavailable: 1
extraVolumeMountCreate: true
extraVolumeName: "varlibdockercontainers"
extraVolumeMountPath: "/var/lib/docker/containers"
Loading