Skip to content
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

feat!: Separate out internal and external nginx controllers #880

Merged
merged 6 commits into from
Jul 31, 2023
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ _Mic check, 1, 2_ - In a few moments applications should be lighting up like Chr

#### 🌐 DNS

The `external-dns` application created in the `networking` namespace will handle creating public DNS records. By default, `echo-server` and the `flux-webhook` are the only public sub-domains exposed. In order to make additional applications public you must set an ingress annotation (`external-dns.alpha.kubernetes.io/target`) like done in the `HelmRelease` for `echo-server`.
The `external-dns` application created in the `networking` namespace will handle creating public DNS records. By default, `echo-server` and the `flux-webhook` are the only public sub-domains exposed. In order to make additional applications public you must set the correct ingress class name and ingress annotations like done in the `HelmRelease` for `echo-server`.

For split DNS to work it is required to have `${bootstrap_cloudflare_domain}` point to the `${bootstrap_k8s_gateway_addr}` load balancer IP address on your home DNS server. This will ensure DNS requests for `${bootstrap_cloudflare_domain}` will only get routed to your `k8s_gateway` service thus providing **internal** DNS resolution to your cluster applications/ingresses from any device that uses your home DNS server.

Expand All @@ -370,7 +370,7 @@ For and example with Pi-Hole apply the following file and restart dnsmasq:
server=/${bootstrap_cloudflare_domain}/${bootstrap_k8s_gateway_addr}
```

Now try to resolve an internal-only domain with `dig @${pi-hole-ip} hajimari.${bootstrap_cloudflare_domain}` it should resolve to your `${bootstrap_ingress_nginx_addr}` IP.
Now try to resolve an internal-only domain with `dig @${pi-hole-ip} hajimari.${bootstrap_cloudflare_domain}` it should resolve to your `${bootstrap_internal_nginx_addr}` IP.

If you're having trouble with DNS be sure to check out these two Github discussions, [Internal DNS](https://github.com/onedr0p/flux-cluster-template/discussions/719) and [Pod DNS resolution broken](https://github.com/onedr0p/flux-cluster-template/discussions/635).

Expand Down
44 changes: 34 additions & 10 deletions bootstrap/tasks/validation/net.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,29 @@
success_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: k8s_gateway address {{ bootstrap_k8s_gateway_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify ingress-nginx
- name: Verify internal nginx
ansible.builtin.assert:
that: bootstrap_ingress_nginx_addr is ansible.utils.ipv4
success_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is valid.
fail_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is invalid.
that: bootstrap_internal_nginx_addr is ansible.utils.ipv4
success_msg: internal nginx address {{ bootstrap_internal_nginx_addr }} is valid.
fail_msg: internal nginx address {{ bootstrap_internal_nginx_addr }} is invalid.

- name: Verify ingress-nginx in node CIDR
- name: Verify internal nginx in node CIDR
ansible.builtin.assert:
that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_ingress_nginx_addr)
success_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: ingress-nginx address {{ bootstrap_ingress_nginx_addr }} is not within {{ bootstrap_node_cidr }}.
that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_internal_nginx_addr)
success_msg: internal nginx address {{ bootstrap_internal_nginx_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: internal nginx address {{ bootstrap_internal_nginx_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify external nginx
ansible.builtin.assert:
that: bootstrap_external_nginx_addr is ansible.utils.ipv4
success_msg: external nginx address {{ bootstrap_external_nginx_addr }} is valid.
fail_msg: external nginx address {{ bootstrap_external_nginx_addr }} is invalid.

- name: Verify external nginx in node CIDR
ansible.builtin.assert:
that: bootstrap_node_cidr | ansible.utils.network_in_usable(bootstrap_external_nginx_addr)
success_msg: external nginx address {{ bootstrap_external_nginx_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: external nginx address {{ bootstrap_external_nginx_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify kube-vip
ansible.builtin.assert:
Expand All @@ -91,9 +103,21 @@
success_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is within {{ bootstrap_node_cidr }}.
fail_msg: kube-vip address {{ bootstrap_kube_vip_addr }} is not within {{ bootstrap_node_cidr }}.

- name: Verify nodes are not the same IPs as k8s_gateway, ingress-nginx or kube-vip
- name: Verify all IP addresses are unique
ansible.builtin.assert:
that: >
[
bootstrap_k8s_gateway_addr,
bootstrap_external_nginx_addr,
bootstrap_internal_nginx_addr,
bootstrap_kube_vip_addr
] | unique | length == 4
success_msg: All IP addresses are unique.
fail_msg: All IP addresses are not unique.

- name: Verify nodes are not the same IPs as k8s_gateway, nginx external/internal or kube-vip
ansible.builtin.assert:
that: item.address not in (bootstrap_k8s_gateway_addr, bootstrap_ingress_nginx_addr, bootstrap_kube_vip_addr)
that: item.address not in (bootstrap_k8s_gateway_addr, bootstrap_external_nginx_addr, bootstrap_internal_nginx_addr, bootstrap_kube_vip_addr)
success_msg: Node address {{ item.address }} is different than k8s_gateway, ingress-nginx or kube-vip.
fail_msg: Node address {{ item.address }} is not different than k8s_gateway, ingress-nginx or kube-vip.
quiet: true
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/tasks/validation/vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
- bootstrap_flux_github_webhook_token
- bootstrap_github_repository_name
- bootstrap_github_username
- bootstrap_ingress_nginx_addr
- bootstrap_external_nginx_addr
- bootstrap_internal_nginx_addr
- bootstrap_ipv6_enabled
- bootstrap_k8s_gateway_addr
- bootstrap_kube_vip_addr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
5 changes: 1 addition & 4 deletions bootstrap/templates/addons/grafana/app/helmrelease.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand All @@ -28,8 +27,6 @@ spec:
dependsOn:
- name: local-path-provisioner
namespace: kube-system
- name: ingress-nginx
namespace: networking
values:
deploymentStrategy:
type: Recreate
Expand Down Expand Up @@ -162,7 +159,7 @@ spec:
enabled: true
ingress:
enabled: true
ingressClassName: nginx
ingressClassName: internal
annotations:
hajimari.io/icon: simple-icons:grafana
hosts:
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/templates/addons/grafana/ks.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
6 changes: 1 addition & 5 deletions bootstrap/templates/addons/hajimari/app/helmrelease.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand All @@ -25,9 +24,6 @@ spec:
retries: 3
uninstall:
keepHistory: false
dependsOn:
- name: ingress-nginx
namespace: networking
values:
hajimari:
title: Apps
Expand All @@ -47,7 +43,7 @@ spec:
ingress:
main:
enabled: true
ingressClassName: nginx
ingressClassName: internal
annotations:
hajimari.io/enable: "false"
hosts:
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/templates/addons/hajimari/ks.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
crds: CreateReplace
remediation:
retries: 3
Expand All @@ -32,8 +31,6 @@ spec:
dependsOn:
- name: local-path-provisioner
namespace: kube-system
- name: ingress-nginx
namespace: networking
values:
crds:
enabled: true
Expand Down Expand Up @@ -117,7 +114,7 @@ spec:
prometheus:
ingress:
enabled: true
ingressClassName: nginx
ingressClassName: internal
annotations:
hajimari.io/appName: Prometheus
hajimari.io/icon: simple-icons:prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand All @@ -25,12 +24,7 @@ spec:
retries: 3
uninstall:
keepHistory: false
dependsOn:
- name: ingress-nginx
namespace: networking
values:
env:
TZ: "${TIMEZONE}"
api:
containers:
args:
Expand Down
3 changes: 1 addition & 2 deletions bootstrap/templates/addons/kubernetes-dashboard/ks.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ metadata:
spec:
dependsOn:
- name: cluster-apps-cert-manager
- name: cluster-apps-ingress-nginx
- name: cluster-apps-metrics-server
path: ./kubernetes/apps/monitoring/kubernetes-dashboard/app
prune: true
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/templates/addons/weave-gitops/ks.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ metadata:
name: flux-webhook
namespace: flux-system
annotations:
external-dns.alpha.kubernetes.io/target: "ingress.${SECRET_DOMAIN}"
external-dns.alpha.kubernetes.io/target: "external.${SECRET_DOMAIN}"
hajimari.io/enable: "false"
spec:
ingressClassName: nginx
ingressClassName: external
rules:
- host: &host "flux-webhook.${SECRET_DOMAIN}"
http:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ spec:
namespace: flux-system
maxHistory: 2
install:
createNamespace: true
remediation:
retries: 3
upgrade:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
sourceRef:
kind: GitRepository
name: home-kubernetes
wait: false # no flux ks dependents
wait: false
interval: 30m
retryInterval: 1m
timeout: 5m
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
originRequest:
http2Origin: true

# https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/configuration/ingress
ingress:
- hostname: "${SECRET_DOMAIN}"
service: https://ingress-nginx-controller.networking.svc.cluster.local:443
service: https://nginx-external-controller.networking.svc.cluster.local:443
originRequest:
originServerName: "ingress.${SECRET_DOMAIN}"
- hostname: "*.${SECRET_DOMAIN}"
service: https://ingress-nginx-controller.networking.svc.cluster.local:443
service: https://nginx-external-controller.networking.svc.cluster.local:443
originRequest:
originServerName: "ingress.${SECRET_DOMAIN}"
- service: http_status:404
Loading