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

[stable/nginx-ingress] Add RBAC support #1235

Merged
merged 10 commits into from
Aug 14, 2017
4 changes: 2 additions & 2 deletions stable/nginx-ingress/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: nginx-ingress
version: 0.7.2
appVersion: 0.9.0-beta.7
version: 0.8.0
appVersion: 0.9.0-beta.11
description: An nginx Ingress controller that uses ConfigMap to store the nginx configuration.
icon: https://upload.wikimedia.org/wikipedia/commons/thumb/c/c5/Nginx_logo.svg/500px-Nginx_logo.svg.png
keywords:
Expand Down
5 changes: 4 additions & 1 deletion stable/nginx-ingress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ Parameter | Description | Default
`controller.config` | nginx ConfigMap entries | none
`controller.hostNetwork` | If the nginx deployment / daemonset should run on the host's network namespace | false
`controller.defaultBackendService` | default 404 backend service; required only if `defaultBackend.enabled = false` | `""`
`controller.electionID` | election ID to use for the status update | `ingress-controller-leader`
`controller.ingressClass` | name of the ingress class to route through this controller | `nginx`
`controller.scope.enabled` | limit the scope of the ingress controller | `false` (watch all namespaces)
`controller.scope.namespace` | namespace to watch for ingress | `""` (use the release namespace)
`controller.serviceAccountName` | Service account to run under | `default`
`controller.extraArgs` | Additional controller container arguments | `{}`
`controller.kind` | install as Deployment or DaemonSet | `Deployment`
`controller.nodeSelector` | node labels for pod assignment | `{}`
Expand Down Expand Up @@ -95,6 +96,8 @@ Parameter | Description | Default
`defaultBackend.service.loadBalancerIP` | IP address to assign to load balancer (if supported) | `""`
`defaultBackend.service.loadBalancerSourceRanges` | list of IP CIDRs allowed access to load balancer (if supported) | `[]`
`defaultBackend.service.type` | type of default backend service to create | `ClusterIP`
`rbac.create` | If true, create & use RBAC resources | `false`
`rbac.serviceAccountName` | ServiceAccount to be used (ignored if rbac.create=true) | `default`
`statsExporter.name` | name of the Prometheus metrics exporter component | `stats-exporter`
`statsExporter.image.repository` | Prometheus metrics exporter container image repository | `quay.io/cy-play/vts-nginx-exporter`
`statsExporter.image.tag` | Prometheus metrics exporter image tag | `v0.0.3`
Expand Down
69 changes: 69 additions & 0 deletions stable/nginx-ingress/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "fullname" . }}
rules:
- apiGroups:
- ""
resources:
- configmaps
- endpoints
- nodes
- pods
- secrets
verbs:
- list
- watch
{{- if and .Values.controller.scope.enabled .Values.controller.scope.namespace }}
- apiGroups:
- ""
resources:
- namespaces
resourceNames:
- "{{ .Values.controller.scope.namespace }}"
verbs:
- get
{{- end }}
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- apiGroups:
- ""
resources:
- services
verbs:
- get
- list
- update
- watch
- apiGroups:
- extensions
resources:
- ingresses
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
- apiGroups:
- extensions
resources:
- ingresses/status
verbs:
- update
{{- end -}}
19 changes: 19 additions & 0 deletions stable/nginx-ingress/templates/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "fullname" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
18 changes: 11 additions & 7 deletions stable/nginx-ingress/templates/controller-daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ metadata:
spec:
template:
metadata:
{{- if .Values.controller.podAnnotations }}
annotations:
{{ toYaml .Values.controller.podAnnotations | indent 8 }}
checksum/config: {{ include (print $.Template.BasePath "/controller-configmap.yaml") . | sha256sum }}
{{- if .Values.controller.podAnnotations }}
{{ toYaml .Values.controller.podAnnotations | indent 8}}
{{- end }}
labels:
app: {{ template "name" . }}
component: "{{ .Values.controller.name }}"
release: {{ .Release.Name }}
spec:
hostNetwork: {{ .Values.controller.hostNetwork }}
{{- if .Values.controller.serviceAccountName }}
serviceAccountName: {{ .Values.controller.serviceAccountName }}
{{- end }}
containers:
- name: {{ template "name" . }}-{{ .Values.controller.name }}
image: "{{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag }}"
Expand All @@ -35,6 +32,12 @@ spec:
{{- if and (contains "0.9" .Values.controller.image.tag) .Values.controller.publishService.enabled }}
- --publish-service={{ template "controller.publishServicePath" . }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --election-id={{ .Values.controller.electionID }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --ingress-class={{ .Values.controller.ingressClass }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --configmap={{ .Release.Namespace }}/{{ template "controller.fullname" . }}
{{- else }}
Expand Down Expand Up @@ -97,7 +100,6 @@ spec:
scheme: HTTP
resources:
{{ toYaml .Values.controller.resources | indent 12 }}

{{- if .Values.controller.stats.enabled }}
- name: {{ template "name" . }}-{{ .Values.statsExporter.name }}
image: "{{ .Values.statsExporter.image.repository }}:{{ .Values.statsExporter.image.tag }}"
Expand All @@ -118,9 +120,11 @@ spec:
resources:
{{ toYaml .Values.statsExporter.resources | indent 12 }}
{{- end }}
hostNetwork: {{ .Values.controller.hostNetwork }}
{{- if .Values.controller.nodeSelector }}
nodeSelector:
{{ toYaml .Values.controller.nodeSelector | indent 8 }}
{{- end }}
serviceAccountName: {{ if .Values.rbac.create }}{{ template "fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
terminationGracePeriodSeconds: 60
{{- end }}
20 changes: 12 additions & 8 deletions stable/nginx-ingress/templates/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,16 @@ spec:
replicas: {{ .Values.controller.replicaCount }}
template:
metadata:
{{- if .Values.controller.podAnnotations }}
annotations:
{{ toYaml .Values.controller.podAnnotations | indent 8 }}
{{- end }}
checksum/config: {{ include (print $.Template.BasePath "/controller-configmap.yaml") . | sha256sum }}
{{- if .Values.controller.podAnnotations }}
{{ toYaml .Values.controller.podAnnotations | indent 8}}
{{- end }}
labels:
app: {{ template "name" . }}
component: "{{ .Values.controller.name }}"
release: {{ .Release.Name }}
spec:
hostNetwork: {{ .Values.controller.hostNetwork }}
{{- if .Values.controller.serviceAccountName }}
serviceAccountName: {{ .Values.controller.serviceAccountName }}
{{- end }}
containers:
- name: {{ template "name" . }}-{{ .Values.controller.name }}
image: "{{ .Values.controller.image.repository }}:{{ .Values.controller.image.tag }}"
Expand All @@ -36,6 +33,12 @@ spec:
{{- if and (contains "0.9" .Values.controller.image.tag) .Values.controller.publishService.enabled }}
- --publish-service={{ template "controller.publishServicePath" . }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --election-id={{ .Values.controller.electionID }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --ingress-class={{ .Values.controller.ingressClass }}
{{- end }}
{{- if (contains "0.9" .Values.controller.image.tag) }}
- --configmap={{ .Release.Namespace }}/{{ template "controller.fullname" . }}
{{- else }}
Expand Down Expand Up @@ -98,7 +101,6 @@ spec:
scheme: HTTP
resources:
{{ toYaml .Values.controller.resources | indent 12 }}

{{- if .Values.controller.stats.enabled }}
- name: {{ template "name" . }}-{{ .Values.statsExporter.name }}
image: "{{ .Values.statsExporter.image.repository }}:{{ .Values.statsExporter.image.tag }}"
Expand All @@ -119,9 +121,11 @@ spec:
resources:
{{ toYaml .Values.statsExporter.resources | indent 12 }}
{{- end }}
hostNetwork: {{ .Values.controller.hostNetwork }}
{{- if .Values.controller.nodeSelector }}
nodeSelector:
{{ toYaml .Values.controller.nodeSelector | indent 8 }}
{{- end }}
serviceAccountName: {{ if .Values.rbac.create }}{{ template "fullname" . }}{{ else }}"{{ .Values.rbac.serviceAccountName }}"{{ end }}
terminationGracePeriodSeconds: 60
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ spec:
app: {{ template "name" . }}
component: "{{ .Values.defaultBackend.name }}"
release: {{ .Release.Name }}
type: ClusterIP
type: "{{ .Values.defaultBackend.service.type }}"
{{- end }}
44 changes: 44 additions & 0 deletions stable/nginx-ingress/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "fullname" . }}
rules:
- apiGroups:
- ""
resources:
- configmaps
- namespaces
- pods
- secrets
verbs:
- get
- apiGroups:
- ""
resources:
- configmaps
resourceNames:
- {{ .Values.controller.electionID }}-{{ .Values.controller.ingressClass }}
verbs:
- get
- update
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
- apiGroups:
- ""
resources:
- endpoints
verbs:
- create
- get
- update
{{- end -}}
19 changes: 19 additions & 0 deletions stable/nginx-ingress/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.rbac.create -}}
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "fullname" . }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: {{ template "fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ template "fullname" . }}
namespace: {{ .Release.Namespace }}
{{- end -}}
11 changes: 11 additions & 0 deletions stable/nginx-ingress/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{- if .Values.rbac.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
name: {{ template "fullname" . }}
{{- end -}}
23 changes: 18 additions & 5 deletions stable/nginx-ingress/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ controller:
##
defaultBackendService: ""

## Optionally specify the secret name for default SSL certificate
## Must be <namespace>/<secret_name>
##
defaultSSLCertificate: ""

## Election ID to use for status update
##
electionID: ingress-controller-leader

## Name of the ingress class to route through this controller
##
ingressClass: nginx

## Allows customization of the external service
## the ingress will be bound to via DNS
publishService:
Expand All @@ -46,11 +59,6 @@ controller:
##
nodeSelector: {}

## Run the controller via this service account
## Ref: https://github.com/kubernetes/ingress/tree/master/examples/rbac/nginx
##
serviceAccountName: ""

## Annotations to be added to controller pods
##
podAnnotations: {}
Expand Down Expand Up @@ -162,6 +170,11 @@ defaultBackend:
servicePort: 80
type: ClusterIP

## Enable RBAC as per https://github.com/kubernetes/ingress/tree/master/examples/rbac/nginx and https://github.com/kubernetes/ingress/issues/266
rbac:
create: false
serviceAccountName: default

## If controller.stats.enabled = true, Prometheus metrics will be exported
## Ref: https://github.com/hnlq715/nginx-vts-exporter
##
Expand Down