Skip to content

WIP: Make CoreDNS manifests v1.8 #8

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

Merged
merged 3 commits into from
Jun 15, 2021
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
189 changes: 189 additions & 0 deletions deploy/helm/kubernetes/manifests/coredns-1.8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: coredns
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:coredns
rules:
- apiGroups:
- ""
resources:
- endpoints
- services
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- apiGroups:
- discovery.k8s.io
resources:
- endpointslices
verbs:
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: system:coredns
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:coredns
subjects:
- kind: ServiceAccount
name: coredns
namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns
namespace: kube-system
data:
Corefile: |
.:53 {
errors
health
ready
kubernetes cluster.local in-addr.arpa ip6.arpa {
pods insecure
fallthrough in-addr.arpa ip6.arpa
}
prometheus :9153
cache 30
loop
reload
loadbalance
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: coredns
namespace: kube-system
labels:
k8s-app: kube-dns
kubernetes.io/name: "CoreDNS"
spec:
replicas: {{ .Values.coredns.replicaCount }}
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
selector:
matchLabels:
k8s-app: kube-dns
template:
metadata:
labels:
k8s-app: kube-dns
spec:
priorityClassName: system-cluster-critical
serviceAccountName: coredns
tolerations:
- key: "CriticalAddonsOnly"
operator: "Exists"
nodeSelector:
beta.kubernetes.io/os: linux
{{- with .Values.coredns.image.pullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 10 }}
{{- end }}
containers:
- name: coredns
{{- with .Values.coredns.image }}
image: "{{ .repository }}{{ if .digest }}@{{ .digest }}{{ else }}:{{ .tag }}{{ end }}"
imagePullPolicy: {{ .pullPolicy }}
{{- end }}
resources:
{{- toYaml .Values.coredns.resources | nindent 10 }}
args: [ "-conf", "/etc/coredns/Corefile" ]
volumeMounts:
- name: config-volume
mountPath: /etc/coredns
readOnly: true
ports:
- containerPort: 53
name: dns
protocol: UDP
- containerPort: 53
name: dns-tcp
protocol: TCP
- containerPort: 9153
name: metrics
protocol: TCP
securityContext:
allowPrivilegeEscalation: false
capabilities:
add:
- NET_BIND_SERVICE
drop:
- all
readOnlyRootFilesystem: true
livenessProbe:
httpGet:
path: /health
port: 8080
scheme: HTTP
initialDelaySeconds: 60
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
readinessProbe:
httpGet:
path: /ready
port: 8181
scheme: HTTP
dnsPolicy: Default
volumes:
- name: config-volume
configMap:
name: coredns
items:
- key: Corefile
path: Corefile
---
apiVersion: v1
kind: Service
metadata:
name: kube-dns
namespace: kube-system
annotations:
prometheus.io/port: "9153"
prometheus.io/scrape: "true"
labels:
k8s-app: kube-dns
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "CoreDNS"
spec:
selector:
k8s-app: kube-dns
clusterIP: {{ template "getCoreDNS" . }}
ports:
- name: dns
port: 53
protocol: UDP
- name: dns-tcp
port: 53
protocol: TCP
- name: metrics
port: 9153
protocol: TCP
9 changes: 4 additions & 5 deletions deploy/helm/kubernetes/scripts/configure-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,23 @@ EOT
# install konnectivity server
kubectl apply -f /manifests/konnectivity-server-rbac.yaml
{{- else }}{{"\n"}}
kubectl delete clusterrolebinding/system:konnectivity-server 2>/dev/null || true
kubectl delete -f /manifests/konnectivity-server-rbac.yaml 2>/dev/null || true
{{- end }}

{{- if .Values.konnectivityAgent.enabled }}{{"\n"}}
# install konnectivity agent
kubectl apply -f /manifests/konnectivity-agent-deployment.yaml -f /manifests/konnectivity-agent-rbac.yaml
{{- else }}{{"\n"}}
# uninstall konnectivity agent
kubectl -n kube-system delete deployment/konnectivity-agent serviceaccount/konnectivity-agent 2>/dev/null || true
kubectl delete -f /manifests/konnectivity-agent-deployment.yaml -f /manifests/konnectivity-agent-rbac.yaml 2>/dev/null || true
{{- end }}

{{- if .Values.coredns.enabled }}{{"\n"}}
# install coredns addon
# TODO: https://github.com/kvaps/kubernetes-in-kubernetes/issues/3
kubeadm init phase addon coredns --config /config/kubeadmcfg.yaml
kubectl apply -f /manifests/coredns.yaml
{{- else }}{{"\n"}}
# uninstall coredns addon
kubectl -n kube-system delete configmap/coredns deployment/coredns 2>/dev/null || true
kubectl delete -f /manifests/coredns.yaml 2>/dev/null || true
{{- end }}

{{- if .Values.kubeProxy.enabled }}{{"\n"}}
Expand Down
13 changes: 13 additions & 0 deletions deploy/helm/kubernetes/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,16 @@ Generate etcd servers list.
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Take the first IP address from the serviceClusterIPRange for the kube-dns service.
*/}}
{{- define "getCoreDNS" -}}
{{- $octetsList := splitList "." .Values.apiServer.serviceClusterIPRange -}}
{{- printf "%d.%d.%d.%d" (index $octetsList 0 | int) (index $octetsList 1 | int) (index $octetsList 2 | int) 10 -}}
{{- end -}}

{{- define "getAPIAddress" -}}
{{- $octetsList := splitList "." .Values.apiServer.serviceClusterIPRange -}}
{{- printf "%d.%d.%d.%d" (index $octetsList 0 | int) (index $octetsList 1 | int) (index $octetsList 2 | int) 1 -}}
{{- end -}}
8 changes: 6 additions & 2 deletions deploy/helm/kubernetes/templates/kubeadm-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
name: pki-admin-client
- mountPath: /scripts
name: scripts
{{- if or .Values.extraManifests .Values.konnectivityServer.enabled .Values.konnectivityAgent.enabled }}
{{- if or .Values.extraManifests .Values.konnectivityServer.enabled .Values.konnectivityAgent.enabled .Values.coredns.enabled }}
- mountPath: /manifests
name: manifests
{{- end }}
Expand All @@ -93,7 +93,7 @@ spec:
configMap:
name: "{{ $fullName }}-kubeadm-scripts"
defaultMode: 0777
{{- if or .Values.extraManifests .Values.konnectivityServer.enabled .Values.konnectivityAgent.enabled }}
{{- if or .Values.extraManifests .Values.konnectivityServer.enabled .Values.konnectivityAgent.enabled .Values.coredns.enabled }}
- name: manifests
projected:
sources:
Expand All @@ -105,6 +105,10 @@ spec:
- configMap:
name: "{{ $fullName }}-konnectivity-manifests"
{{- end }}
{{- if .Values.coredns.enabled }}
- configMap:
name: "{{ $fullName }}-coredns-manifests"
{{- end }}
{{- end }}
- name: config
configMap:
Expand Down
13 changes: 13 additions & 0 deletions deploy/helm/kubernetes/templates/kubedns-manifests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.coredns.enabled }}
{{- $fullName := include "kubernetes.fullname" . -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $fullName }}-coredns-manifests
data:
{{- if .Values.coredns.enabled }}
coredns.yaml: |
{{- tpl (.Files.Get "manifests/coredns-1.8.yaml") . | nindent 4 }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason for specifying version in filename?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on whether you'd like to support several CoreDNS versions simultaneously. Because CoreDNS version does not have strict mapping on Kubernetes version in fact.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on whether you'd like to support several CoreDNS versions simultaneously

How are two coredns versions can act together in single cluster?

CoreDNS version does not have strict mapping on Kubernetes version in fact.

That's true, but it has some defaults in kubeadm:
https://github.com/kubernetes/kubernetes/blob/5e58841cce77d4bc13713ad2b91fa0d961e69192/cluster/addons/dns/coredns/coredns.yaml.base#L134-L135

{{- end }}
{{- end }}
6 changes: 3 additions & 3 deletions deploy/helm/kubernetes/templates/kubernetes-certs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ spec:
{{- end }}
ipAddresses:
- "127.0.0.1"
- "10.96.0.1"
- "{{- template "getAPIAddress" . }}"
{{- with .Values.apiServer.service.loadBalancerIP }}
{{- if not (has . $.Values.apiServer.certSANs.ipAddresses) }}
- {{ . | quote }}
Expand Down Expand Up @@ -122,7 +122,7 @@ spec:
{{- end }}
ipAddresses:
- "127.0.0.1"
- "10.96.0.1"
- "{{- template "getAPIAddress" . }}"
{{- with .Values.apiServer.service.loadBalancerIP }}
{{- if not (has . $.Values.apiServer.certSANs.ipAddresses) }}
- {{ . | quote }}
Expand Down Expand Up @@ -164,7 +164,7 @@ spec:
{{- end }}
ipAddresses:
- "127.0.0.1"
- "10.96.0.1"
- "{{- template "getAPIAddress" . }}"
{{- with .Values.apiServer.service.loadBalancerIP }}
{{- if not (has . $.Values.apiServer.certSANs.ipAddresses) }}
- {{ . | quote }}
Expand Down
12 changes: 12 additions & 0 deletions deploy/helm/kubernetes/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ kubeProxy:

coredns:
enabled: true
image:
repository: coredns/coredns
tag: 1.8.3
pullPolicy: IfNotPresent
pullSecrets: []
replicaCount: 2
resources:
limits:
memory: 170Mi
requests:
cpu: 100m
memory: 70Mi

konnectivityServer:
enabled: false
Expand Down