diff --git a/addons/nginx-ingress/aws/default-backend/deployment.yaml b/addons/nginx-ingress/aws/default-backend/deployment.yaml new file mode 100644 index 00000000..f25afe40 --- /dev/null +++ b/addons/nginx-ingress/aws/default-backend/deployment.yaml @@ -0,0 +1,36 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: default-backend + namespace: ingress +spec: + replicas: 1 + template: + metadata: + labels: + name: default-backend + phase: prod + spec: + containers: + - name: default-backend + # Any image is permissable as long as: + # 1. It serves a 404 page at / + # 2. It serves 200 on a /healthz endpoint + image: gcr.io/google_containers/defaultbackend:1.0 + ports: + - containerPort: 8080 + resources: + limits: + cpu: 10m + memory: 20Mi + requests: + cpu: 10m + memory: 20Mi + livenessProbe: + httpGet: + path: /healthz + port: 8080 + scheme: HTTP + initialDelaySeconds: 30 + timeoutSeconds: 5 + terminationGracePeriodSeconds: 60 diff --git a/addons/nginx-ingress/aws/default-backend/service.yaml b/addons/nginx-ingress/aws/default-backend/service.yaml new file mode 100644 index 00000000..87997aba --- /dev/null +++ b/addons/nginx-ingress/aws/default-backend/service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: default-backend + namespace: ingress +spec: + type: ClusterIP + selector: + name: default-backend + phase: prod + ports: + - name: http + protocol: TCP + port: 80 + targetPort: 8080 diff --git a/addons/nginx-ingress/aws/deployment.yaml b/addons/nginx-ingress/aws/deployment.yaml new file mode 100644 index 00000000..a5f7bf77 --- /dev/null +++ b/addons/nginx-ingress/aws/deployment.yaml @@ -0,0 +1,61 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: nginx-ingress-controller + namespace: ingress +spec: + replicas: 2 + strategy: + rollingUpdate: + maxUnavailable: 1 + template: + metadata: + labels: + name: nginx-ingress-controller + phase: prod + spec: + nodeSelector: + node-role.kubernetes.io/node: "" + containers: + - name: nginx-ingress-controller + image: gcr.io/google_containers/nginx-ingress-controller:0.9.0-beta.11 + args: + - /nginx-ingress-controller + - --default-backend-service=$(POD_NAMESPACE)/default-backend + - --ingress-class=public + # use downward API + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: POD_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + ports: + - name: http + containerPort: 80 + hostPort: 80 + - name: https + containerPort: 443 + hostPort: 443 + - name: health + containerPort: 10254 + hostPort: 10254 + readinessProbe: + httpGet: + path: /healthz + port: 10254 + scheme: HTTP + livenessProbe: + initialDelaySeconds: 11 + timeoutSeconds: 1 + httpGet: + path: /healthz + port: 10254 + scheme: HTTP + hostNetwork: true + dnsPolicy: ClusterFirst + restartPolicy: Always + terminationGracePeriodSeconds: 60 diff --git a/addons/nginx-ingress/aws/namespace.yaml b/addons/nginx-ingress/aws/namespace.yaml new file mode 100644 index 00000000..b40cd8b2 --- /dev/null +++ b/addons/nginx-ingress/aws/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: ingress diff --git a/addons/nginx-ingress/aws/rbac/cluster-role-binding.yaml b/addons/nginx-ingress/aws/rbac/cluster-role-binding.yaml new file mode 100644 index 00000000..20494d2f --- /dev/null +++ b/addons/nginx-ingress/aws/rbac/cluster-role-binding.yaml @@ -0,0 +1,12 @@ +kind: ClusterRoleBinding +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: ingress +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: ingress +subjects: + - kind: ServiceAccount + namespace: ingress + name: default diff --git a/addons/nginx-ingress/aws/rbac/cluster-role.yaml b/addons/nginx-ingress/aws/rbac/cluster-role.yaml new file mode 100644 index 00000000..696a6920 --- /dev/null +++ b/addons/nginx-ingress/aws/rbac/cluster-role.yaml @@ -0,0 +1,51 @@ +apiVersion: rbac.authorization.k8s.io/v1beta1 +kind: ClusterRole +metadata: + name: ingress +rules: + - apiGroups: + - "" + resources: + - configmaps + - endpoints + - nodes + - pods + - secrets + verbs: + - list + - watch + - apiGroups: + - "" + resources: + - nodes + verbs: + - get + - apiGroups: + - "" + resources: + - services + verbs: + - get + - list + - watch + - apiGroups: + - "extensions" + resources: + - ingresses + verbs: + - get + - list + - watch + - apiGroups: + - "" + resources: + - events + verbs: + - create + - patch + - apiGroups: + - "extensions" + resources: + - ingresses/status + verbs: + - update diff --git a/addons/nginx-ingress/aws/rbac/role-binding.yaml b/addons/nginx-ingress/aws/rbac/role-binding.yaml new file mode 100644 index 00000000..ecd04049 --- /dev/null +++ b/addons/nginx-ingress/aws/rbac/role-binding.yaml @@ -0,0 +1,13 @@ +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: ingress + namespace: ingress +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: ingress +subjects: + - kind: ServiceAccount + namespace: ingress + name: default diff --git a/addons/nginx-ingress/aws/rbac/role.yaml b/addons/nginx-ingress/aws/rbac/role.yaml new file mode 100644 index 00000000..366251ae --- /dev/null +++ b/addons/nginx-ingress/aws/rbac/role.yaml @@ -0,0 +1,41 @@ +kind: Role +apiVersion: rbac.authorization.k8s.io/v1beta1 +metadata: + name: ingress + namespace: ingress +rules: + - apiGroups: + - "" + resources: + - configmaps + - pods + - secrets + verbs: + - get + - apiGroups: + - "" + resources: + - configmaps + resourceNames: + # Defaults to "-" + # Here: "-" + # This has to be adapted if you change either parameter + # when launching the nginx-ingress-controller. + - "ingress-controller-leader-public" + verbs: + - get + - update + - apiGroups: + - "" + resources: + - configmaps + verbs: + - create + - apiGroups: + - "" + resources: + - endpoints + verbs: + - get + - create + - update diff --git a/addons/nginx-ingress/aws/service.yaml b/addons/nginx-ingress/aws/service.yaml new file mode 100644 index 00000000..88afc467 --- /dev/null +++ b/addons/nginx-ingress/aws/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx-ingress-controller + namespace: ingress +spec: + type: ClusterIP + selector: + name: nginx-ingress-controller + phase: prod + ports: + - name: http + protocol: TCP + port: 80 + targetPort: 80 + - name: https + protocol: TCP + port: 443 + targetPort: 443 diff --git a/docs/addons/ingress.md b/docs/addons/ingress.md index d6bc5abe..fa8e1915 100644 --- a/docs/addons/ingress.md +++ b/docs/addons/ingress.md @@ -2,6 +2,66 @@ Nginx Ingress controller pods accept and demultiplex HTTP, HTTPS, TCP, or UDP traffic to backend services. Ingress controllers watch the Kubernetes API for Ingress resources and update their configuration accordingly. Ingress resources for HTTP(S) applications support virtual hosts (FQDNs), path rules, TLS termination, and SNI. +## AWS + +On AWS, an elastic load balancer distributes traffic across worker nodes (i.e. an auto-scaling group) running an Ingress controller deployment on host ports 80 and 443. Firewall rules allow traffic to ports 80 and 443. Health check rules ensure only workers with a health Ingress controller receive traffic. + +Create the Ingress controller deployment, service, RBAC roles, RBAC bindings, default backend, and namespace. + +``` +kubectl apply -R addons/nginx-ingress/aws +``` + +For each application, add a DNS CNAME resolving to the ELB's DNS record. + +``` +app1.example.com -> tempest-ingress.123456.us-west2.elb.amazonaws.com +aap2.example.com -> tempest-ingress.123456.us-west2.elb.amazonaws.com +app3.example.com -> tempest-ingress.123456.us-west2.elb.amazonaws.com +``` + +Find the ELB's DNS name through the console or use the Typhoon module's output `ingress_dns_name`. For example, you might use Terraform to manage a Google Cloud DNS record: + +```tf +resource "google_dns_record_set" "some-application" { + # DNS zone name + managed_zone = "example-zone" + + # DNS record + name = "app.example.com." + type = "CNAME" + ttl = 300 + rrdatas = ["${module.aws-tempest.ingress_dns_name}."] +} +``` + +## Digital Ocean + +On Digital Ocean, a DNS A record (e.g. `nemo-workers.example.com`) resolves to each worker[^1] running an Ingress controller DaemonSet on host ports 80 and 443. Firewall rules allow IPv4 and IPv6 traffic to ports 80 and 443. + +Create the Ingress controller daemonset, service, RBAC roles, RBAC bindings, default backend, and namespace. + +``` +kubectl apply -R addons/nginx-ingress/digital-ocean +``` + +For each application, add a CNAME record resolving to the worker(s) DNS record. Use the Typhoon module's output `workers_dns` to find the worker DNS value. For example, you might use Terraform to manage a Google Cloud DNS record: + +```tf +resource "google_dns_record_set" "some-application" { + # DNS zone name + managed_zone = "example-zone" + + # DNS record + name = "app.example.com." + type = "CNAME" + ttl = 300 + rrdatas = ["${module.digital-ocean-nemo.workers_dns}."] +} +``` + +[^1]: Digital Ocean does offers load balancers. We've opted not to use them to keep the Digital Ocean setup simple and cheap for developers. + ## Google Cloud On Google Cloud, a network load balancer distributes traffic across worker nodes (i.e. a target pool of backends) running an Ingress controller deployment on host ports 80 and 443. Firewall rules allow traffic to ports 80 and 443. Health check rules ensure the target pool only includes worker nodes with a healthy Nginx Ingress controller. @@ -12,7 +72,7 @@ Create the Ingress controller deployment, service, RBAC roles, RBAC bindings, de kubectl apply -R addons/nginx-ingress/google-cloud ``` -Add a DNS record resolving to the network load balancer's IPv4 address for each application. +For each application, add a DNS record resolving to the network load balancer's IPv4 address. ``` app1.example.com -> 11.22.33.44 @@ -35,33 +95,6 @@ resource "google_dns_record_set" "some-application" { } ``` -## Digital Ocean - -On Digital Ocean, a DNS A record (e.g. `nemo-workers.example.com`) resolves to each worker[^1] running an Ingress controller DaemonSet on host ports 80 and 443. Firewall rules allow IPv4 and IPv6 traffic to ports 80 and 443. - -Create the Ingress controller daemonset, service, RBAC roles, RBAC bindings, default backend, and namespace. - -``` -kubectl apply -R addons/nginx-ingress/digital-ocean -``` - -Add a CNAME record to the worker DNS record for each application. Use the Typhoon module's output `workers_dns` to find the worker DNS value. For example, you might use Terraform to manage a Google Cloud DNS record: - -```tf -resource "google_dns_record_set" "some-application" { - # DNS zone name - managed_zone = "example-zone" - - # DNS record - name = "app.example.com." - type = "CNAME" - ttl = 300 - rrdatas = ["${module.digital-ocean-nemo.workers_dns}."] -} -``` - -[^1]: Digital Ocean does offers load balancers. We've opted not to use them to keep the Digital Ocean setup simple and cheap for developers. - ## Bare-Metal On bare-metal, routing traffic to Ingress controller pods can be done in number of ways.