Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Adds a generic CoreDNS chart (#785)
Browse files Browse the repository at this point in the history
* CoreDNS

Adds a basic CoreDNS chart based off the project deployment
documentation

* Made CoreDNS chart generic to deploy in multiple scenarios

* Address review comments for CoreDNS chart
  • Loading branch information
Shashidhara T D authored and lachie83 committed Apr 3, 2017
1 parent d763d99 commit 5348297
Show file tree
Hide file tree
Showing 9 changed files with 376 additions and 0 deletions.
21 changes: 21 additions & 0 deletions stable/coredns/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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
*~
# Various IDEs
.project
.idea/
*.tmproj
16 changes: 16 additions & 0 deletions stable/coredns/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: coredns
version: 0.1.0
description: CoreDNS is a DNS server that chains middleware and provides Kubernetes DNS Services
keywords:
- coredns
- dns
- kubedns
home: https://coredns.io
icon: https://raw.githubusercontent.com/coredns/logo/master/Icon/CoreDNS_Colour_Icon.svg
sources:
- https://github.com/coredns/coredns
maintainers:
- name: Acaleph
email: [email protected]
- name: Shashidhara TD
email: [email protected]
82 changes: 82 additions & 0 deletions stable/coredns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
CoreDNS
=======

CoreDNS is a DNS server that chains middleware and provides DNS Services

TL;DR;
------

```console
$ helm install --name coredns --namespace=kube-system stable/coredns
```

Introduction
------------

This chart bootstraps a [CoreDNS](https://github.com/coredns/coredns) deployment on a [Kubernetes](http:https://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. This chart will provide DNS Services and can be deployed in multiple configuration to support various scenarios listed below:

- CoreDNS as a cluster dns service and a drop-in replacement for Kube/SkyDNS. This is the default mode and CoreDNS is deployed as cluster-service in kube-system namespace. This mode is chosen by setting `isClusterService` to true.
- CoreDNS as an external dns service. In this mode CoreDNS is deployed as any kubernetes app in user specified namespace. The CoreDNS service can be exposed outside the cluster by using using either the NodePort or LoadBalancer type of service. This mode is chosen by setting `isClusterService` to false.
- CoreDNS as an external dns provider for kubernetes federation. This is a sub case of 'external dns service' which uses etcd middleware for CoreDNS backend. This deployment mode as a dependency on `etcd-operator` chart, which needs to be pre-installed. To use this deployment mode use below configuration file to override default values.
```
isClusterService: false
serviceType: "NodePort"
middleware:
kubernetes:
enabled: false
etcd:
enabled: true
zones:
- "<example.io>"
endpoint: "http:https://<etcd-cluster>:2379"
```

Prerequisites
-------------

- Kubernetes 1.4+ with Beta APIs enabled

Installing the Chart
--------------------

The chart can be installed as follows:

```console
$ helm install --name coredns --namespace=kube-system stable/coredns
```

The command deploys CoreDNS on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists various ways to override default configuration during deployment.

> **Tip**: List all releases using `helm list`
Uninstalling the Chart
----------------------

To uninstall/delete the `my-release` deployment:

```console
$ helm delete coredns
```

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration
-------------

See `values.yaml` for configuration notes. Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

```console
$ helm install --name coredns \
--set middleware.prometheus.enabled=false \
stable/coredns
```

The above command disables the Prometheus middleware.

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,

```console
$ helm install --name coredns -f values.yaml stable/coredns
```

> **Tip**: You can use the default [values.yaml](values.yaml)
30 changes: 30 additions & 0 deletions stable/coredns/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if .Values.isClusterService }}
CoreDNS is now running in the cluster as a cluster-service.
{{- else }}
CoreDNS is now running in the cluster.
It can be accessed using the below endpoint
{{- if contains "NodePort" .Values.serviceType }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo "$NODE_IP:$NODE_PORT"
{{- else if contains "LoadBalancer" .Values.serviceType }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}'

export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo $SERVICE_IP
{{- else if contains "ClusterIP" .Values.serviceType }}
"{{ template "fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local"
from within the cluster
{{- end }}
{{- end }}

It can be tested with the following:

1. Launch a Pod with DNS tools:

kubectl run -it --rm --restart=Never --image=infoblox/dnstools:latest dnstools

2. Query the DNS server:

/ # host kubernetes
16 changes: 16 additions & 0 deletions stable/coredns/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "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).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
44 changes: 44 additions & 0 deletions stable/coredns/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}
data:
Corefile: |-
.:53 {
{{- range $key, $middleware := .Values.middleware }}
{{- if $middleware.enabled }}
{{- if eq "kubernetes" $key }}
kubernetes {{ $middleware.clusterDomain }} {
cidrs {{ $middleware.clusterCidr }}
}
{{- end }}
{{- if eq "etcd" $key }}
etcd {{ range $middleware.zones }}{{ . }} {{ end }}{
{{ if $middleware.path }}path {{ $middleware.path }}{{ end }}
endpoint {{ $middleware.endpoint }}
}
{{- end }}
{{- if eq "loadbalance" $key }}
loadbalance {{ default "round_robin" $middleware.policy }}
{{- end }}
{{- if eq "log" $key }}
log {{ default "stdout" $middleware.file }}
{{- end }}
{{- if eq "errors" $key }}
errors {{ default "stderr" $middleware.file }}
{{- end }}
{{- if eq "health" $key }}
health
{{- end }}
{{- if eq "prometheus" $key }}
prometheus localhost:{{ $middleware.port }}
{{- end }}
{{- if eq "proxy" $key }}
proxy . /etc/resolv.conf
{{- end }}
{{- if eq "cache" $key }}
cache 30
{{- end }}
{{- end }}
{{- end }}
}
72 changes: 72 additions & 0 deletions stable/coredns/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ template "fullname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
{{- else }}
app: {{ template "fullname" . }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
{{- else }}
app: {{ template "fullname" . }}
{{- end }}
template:
metadata:
labels:
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
{{- else }}
app: {{ template "fullname" . }}
{{- end }}
release: {{ .Release.Name | quote }}
annotations:
{{- if .Values.isClusterService }}
scheduler.alpha.kubernetes.io/critical-pod: ''
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
{{- end }}
spec:
containers:
- name: "coredns"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
resources:
{{ toYaml .Values.resources | indent 10 }}
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
livenessProbe:
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
volumes:
- name: config-volume
configMap:
name: {{ template "fullname" . }}
items:
- key: Corefile
path: Corefile
38 changes: 38 additions & 0 deletions stable/coredns/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
{{- else }}
app: {{ template "fullname" . }}
{{- end }}
annotations:
{{- if .Values.middleware.prometheus.enabled }}
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.middleware.prometheus.port | quote }}
{{- end }}
spec:
selector:
{{- if .Values.isClusterService }}
k8s-app: {{ .Chart.Name | quote }}
{{- else }}
app: {{ template "fullname" . }}
{{- end }}
{{- if .Values.isClusterService }}
clusterIP: {{ .Values.middleware.kubernetes.clusterIP }}
{{- end }}
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
type: {{ default "ClusterIP" .Values.serviceType }}
57 changes: 57 additions & 0 deletions stable/coredns/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Default values for coredns.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: coredns/coredns
tag: "006"
pullPolicy: IfNotPresent

resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi

# isClusterService specifies whether chart should be deployed as cluster-service or normal k8s app.
isClusterService: true

# serviceType specifies type of service to be created for this chart.
serviceType: "ClusterIP"

# middleware configuration of CoreDNS refer to https://github.com/coredns/coredns/tree/master/middleware
# for all specific details. set enabled to true/false to enable/disable a middleware.
middleware:
kubernetes:
enabled: true
clusterCidr: "10.3.0.0/24"
clusterDomain: "cluster.local"
clusterIP:
prometheus:
enabled: true
port: "9153"
errors:
enabled: true
file: "stderr"
log:
enabled: false
file: "stdout"
health:
enabled: true
proxy:
enabled: true
cache:
enabled: true
loadbalance:
enabled: true
policy: "round_robin"
etcd:
enabled: false
zones:
- "k8s.io"
path: "/skydns"
endpoint: "http:https://localhost:2379"

0 comments on commit 5348297

Please sign in to comment.