Skip to content

Commit dbbb214

Browse files
committed
[local-preview] Support 127-0-0-1.nip.io for DOMAIN
Due to the way docker works in non-native platforms, It is very hard to have a consistent experience across all platforms as we can't just use the [docker bridge netwrok IP's in non-native platforms](https://docs.docker.com/desktop/networking/). This means that users have to search their Host IP, and use It to get up and working [which we tried, but understand that it's not a good UX](https://github.com/gitpod-io/website/pull/2349). But users can use `127-0-0-1.nip.io` as the DOMAIN which resolves to `127.0.0.1` and is available in all platforms as its `localhost`. This works well and good for all user communication but internal communication fails as `127-0-0-1.nip.io` for them is something else. So, This PR fixes that by adding new coredns `gitpod.db` coredns config essentially asking to route all `127-0-0-1.nip.io` to `proxy.default.svc.cluster.local`. [As k3s does not yet support overriding coredns config in a sane-way](k3s-io/k3s#462) ,We instead skip the default coredns by adding `coredns.yaml.skip` file, and adding our own `custom-coredns.yaml` which is just plain `coredns.yaml` that comes with `k3s`, added with gitpod config. Signed-off-by: Tarun Pothulapati <tarun@gitpod.io>
1 parent aa3a2ba commit dbbb214

File tree

2 files changed

+217
-0
lines changed

2 files changed

+217
-0
lines changed

install/preview/entrypoint.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ for f in /var/lib/rancher/k3s/server/manifests/gitpod/*StatefulSet*.yaml; do yq
133133
# removing init container from ws-daemon (systemd and Ubuntu)
134134
yq eval-all -i 'del(.spec.template.spec.initContainers[0])' /var/lib/rancher/k3s/server/manifests/gitpod/*_DaemonSet_ws-daemon.yaml
135135

136+
touch /var/lib/rancher/k3s/server/manifests/coredns.yaml.skip
137+
mv -f /app/manifests/coredns.yaml /var/lib/rancher/k3s/server/manifests/custom-coredns.yaml
138+
136139
for f in /var/lib/rancher/k3s/server/manifests/gitpod/*.yaml; do (cat "$f"; echo) >> /var/lib/rancher/k3s/server/manifests/gitpod.yaml; done
137140
rm -rf /var/lib/rancher/k3s/server/manifests/gitpod
138141

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
# Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2+
# Licensed under the MIT License. See License-MIT.txt in the project root for license information.
3+
4+
apiVersion: v1
5+
kind: ServiceAccount
6+
metadata:
7+
name: coredns
8+
namespace: kube-system
9+
---
10+
apiVersion: rbac.authorization.k8s.io/v1beta1
11+
kind: ClusterRole
12+
metadata:
13+
labels:
14+
kubernetes.io/bootstrapping: rbac-defaults
15+
name: system:coredns
16+
rules:
17+
- apiGroups:
18+
- ""
19+
resources:
20+
- endpoints
21+
- services
22+
- pods
23+
- namespaces
24+
verbs:
25+
- list
26+
- watch
27+
- apiGroups:
28+
- discovery.k8s.io
29+
resources:
30+
- endpointslices
31+
verbs:
32+
- list
33+
- watch
34+
---
35+
apiVersion: rbac.authorization.k8s.io/v1beta1
36+
kind: ClusterRoleBinding
37+
metadata:
38+
annotations:
39+
rbac.authorization.kubernetes.io/autoupdate: "true"
40+
labels:
41+
kubernetes.io/bootstrapping: rbac-defaults
42+
name: system:coredns
43+
roleRef:
44+
apiGroup: rbac.authorization.k8s.io
45+
kind: ClusterRole
46+
name: system:coredns
47+
subjects:
48+
- kind: ServiceAccount
49+
name: coredns
50+
namespace: kube-system
51+
---
52+
apiVersion: v1
53+
kind: ConfigMap
54+
metadata:
55+
name: coredns
56+
namespace: kube-system
57+
data:
58+
gitpod.db: |
59+
; 127-0-0-1.nip.io test file
60+
127-0-0-1.nip.io. IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
61+
127-0-0-1.nip.io. IN CNAME proxy.default.svc.cluster.local.
62+
*.127-0-0-1.nip.io. IN CNAME proxy.default.svc.cluster.local.
63+
*.ws.127-0-0-1.nip.io. IN CNAME proxy.default.svc.cluster.local.
64+
Corefile: |
65+
.:53 {
66+
errors
67+
health
68+
ready
69+
# extra configuration for `127-0-0-1.nip.io`
70+
file /etc/coredns/gitpod.db 127-0-0-1.nip.io
71+
kubernetes cluster.local in-addr.arpa ip6.arpa {
72+
pods insecure
73+
fallthrough in-addr.arpa ip6.arpa
74+
}
75+
hosts /etc/coredns/NodeHosts {
76+
ttl 60
77+
reload 15s
78+
fallthrough
79+
}
80+
prometheus :9153
81+
forward . /etc/resolv.conf
82+
cache 30
83+
loop
84+
reload
85+
loadbalance
86+
}
87+
---
88+
apiVersion: apps/v1
89+
kind: Deployment
90+
metadata:
91+
name: coredns
92+
namespace: kube-system
93+
labels:
94+
k8s-app: kube-dns
95+
kubernetes.io/name: "CoreDNS"
96+
spec:
97+
#replicas: 1
98+
strategy:
99+
type: RollingUpdate
100+
rollingUpdate:
101+
maxUnavailable: 1
102+
selector:
103+
matchLabels:
104+
k8s-app: kube-dns
105+
template:
106+
metadata:
107+
labels:
108+
k8s-app: kube-dns
109+
spec:
110+
priorityClassName: "system-cluster-critical"
111+
serviceAccountName: coredns
112+
tolerations:
113+
- key: "CriticalAddonsOnly"
114+
operator: "Exists"
115+
- key: "node-role.kubernetes.io/control-plane"
116+
operator: "Exists"
117+
effect: "NoSchedule"
118+
- key: "node-role.kubernetes.io/master"
119+
operator: "Exists"
120+
effect: "NoSchedule"
121+
nodeSelector:
122+
beta.kubernetes.io/os: linux
123+
containers:
124+
- name: coredns
125+
image: rancher/mirrored-coredns-coredns:1.9.1
126+
imagePullPolicy: IfNotPresent
127+
resources:
128+
limits:
129+
memory: 170Mi
130+
requests:
131+
cpu: 100m
132+
memory: 70Mi
133+
args: [ "-conf", "/etc/coredns/Corefile" ]
134+
volumeMounts:
135+
- name: config-volume
136+
mountPath: /etc/coredns
137+
readOnly: true
138+
ports:
139+
- containerPort: 53
140+
name: dns
141+
protocol: UDP
142+
- containerPort: 53
143+
name: dns-tcp
144+
protocol: TCP
145+
- containerPort: 9153
146+
name: metrics
147+
protocol: TCP
148+
securityContext:
149+
allowPrivilegeEscalation: false
150+
capabilities:
151+
add:
152+
- NET_BIND_SERVICE
153+
drop:
154+
- all
155+
readOnlyRootFilesystem: true
156+
livenessProbe:
157+
httpGet:
158+
path: /health
159+
port: 8080
160+
scheme: HTTP
161+
initialDelaySeconds: 60
162+
periodSeconds: 10
163+
timeoutSeconds: 1
164+
successThreshold: 1
165+
failureThreshold: 3
166+
readinessProbe:
167+
httpGet:
168+
path: /ready
169+
port: 8181
170+
scheme: HTTP
171+
initialDelaySeconds: 0
172+
periodSeconds: 2
173+
timeoutSeconds: 1
174+
successThreshold: 1
175+
failureThreshold: 3
176+
dnsPolicy: Default
177+
volumes:
178+
- name: config-volume
179+
configMap:
180+
name: coredns
181+
items:
182+
- key: gitpod.db
183+
path: gitpod.db
184+
- key: Corefile
185+
path: Corefile
186+
- key: NodeHosts
187+
path: NodeHosts
188+
---
189+
apiVersion: v1
190+
kind: Service
191+
metadata:
192+
name: kube-dns
193+
namespace: kube-system
194+
annotations:
195+
prometheus.io/port: "9153"
196+
prometheus.io/scrape: "true"
197+
labels:
198+
k8s-app: kube-dns
199+
kubernetes.io/cluster-service: "true"
200+
kubernetes.io/name: "CoreDNS"
201+
spec:
202+
selector:
203+
k8s-app: kube-dns
204+
clusterIP: 10.43.0.10
205+
ports:
206+
- name: dns
207+
port: 53
208+
protocol: UDP
209+
- name: dns-tcp
210+
port: 53
211+
protocol: TCP
212+
- name: metrics
213+
port: 9153
214+
protocol: TCP

0 commit comments

Comments
 (0)