Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 20300c4

Browse files
authoredDec 1, 2022
Merge pull request #29 from monzo/gateway-pod-env-configuration
Configure gateway pod definitions with env vars
2 parents a2cbbf3 + 8269bcc commit 20300c4

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed
 

‎README.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# egress-operator
22
An operator to produce egress gateway pods and control access to them with network policies, and a coredns plugin to route egress traffic to these pods.
33

4-
The idea is that instead of authorizing egress traffic with protocol inspection,
4+
The idea is that instead of authorizing egress traffic with protocol inspection,
55
you instead create a internal clusterIP for every external service you use, lock
6-
it down to only a few pods via a network policy, and then set up your dns server
6+
it down to only a few pods via a network policy, and then set up your dns server
77
to resolve the external service to that clusterIP.
88

99
Built with kubebuilder: https://book.kubebuilder.io/
@@ -22,15 +22,15 @@ In the `egress-operator-system` namespace, it creates:
2222
2. Your local system must have a recent version of `golang` for building the code, which you can install by following instructions [here](https://golang.org/doc/install).
2323
3. Your local system must have Kubebuilder for code generation, which you can install by following instructions [here](https://book.kubebuilder.io/quick-start.html).
2424
4. Your local system must have Kustomize for building the Kubernetes manifests, which you can install by following instructions [here](https://kubernetes-sigs.github.io/kustomize/installation/).
25-
5. Your cluster must be running CoreDNS instead of kube-dns, which may not be the case if you are using a managed Kubernetes service. [This article](https://medium.com/google-cloud/using-coredns-on-gke-3973598ab561) provides some help for GCP Kubernetes Engine, and guidance for AWS Elastic Kubernetes Service can be found [here](https://docs.aws.amazon.com/eks/latest/userguide/coredns.html).
25+
5. Your cluster must be running CoreDNS instead of kube-dns, which may not be the case if you are using a managed Kubernetes service. [This article](https://medium.com/google-cloud/using-coredns-on-gke-3973598ab561) provides some help for GCP Kubernetes Engine, and guidance for AWS Elastic Kubernetes Service can be found [here](https://docs.aws.amazon.com/eks/latest/userguide/coredns.html).
2626

2727
## Installing
2828

2929
### Testing locally against a remote cluster
3030

3131
```bash
3232
make run
33-
```
33+
```
3434
This creates an ExternalService object to see the controller-manager creating managed resources in the remote cluster.
3535

3636
### Setting up CoreDNS plugin
@@ -132,9 +132,49 @@ spec:
132132
# ensure your internal IP range is allowed here
133133
# traffic to external IPs will not be allowed from this namespace.
134134
# therefore, pods will have to use egress gateways
135-
cidr: 10.0.0.0/8
135+
cidr: 10.0.0.0/8
136136
```
137137
138-
If you already have a default deny egress policy, the above won't be needed. You'll instead want to explicitly allow
138+
If you already have a default deny egress policy, the above won't be needed. You'll instead want to explicitly allow
139139
egress from your pods to all gateway pods. The ingress policies on gateway pods will ensure that only correct traffic is
140140
allowed.
141+
142+
### Configuration
143+
144+
Global configuration of the operator is set using environment variables.
145+
146+
Node Selectors and Taint tolerations can be added to gateway pods to ensure pods
147+
run on nodes that are permitted to access the internet. Example:
148+
149+
```yaml
150+
env:
151+
- name: NODE_SELECTOR_KEY
152+
value: role
153+
- name: NODE_SELECTOR_VALUE
154+
value: egress-pods
155+
- name: TAINT_TOLERATION_KEY
156+
value: egress-pods
157+
- name: TAINT_TOLERATION_VALUE
158+
value: "true"
159+
```
160+
161+
Results in this gateway pod configuration:
162+
163+
```yaml
164+
spec:
165+
nodeSelector:
166+
role: egress-pods
167+
tolerations:
168+
- effect: NoSchedule
169+
key: egress-pods
170+
value: "true"
171+
...
172+
```
173+
174+
| Variable name | Default | Description |
175+
| ---------------------- | --------------------------------- | -------------------------------------------------- |
176+
| ENVOY_IMAGE | `envoyproxy/envoy-alpine:v1.16.5` | Name of the Envoy Proxy image to use |
177+
| TAINT_TOLERATION_KEY | Empty, no tolerations applied | Toleration key to apply to gateway pods |
178+
| TAINT_TOLERATION_VALUE | Empty, no tolerations applied | Toleration value to apply to gateway pods |
179+
| NODE_SELECTOR_KEY | Empty, no node selector added | Node selector label key to apply to gateway pods |
180+
| NODE_SELECTOR_VALUE | Empty, no node selector added | Node selector label value to apply to gateway pods |

‎controllers/deployment.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"context"
5+
"os"
56
"strconv"
67

78
"github.com/golang/protobuf/proto"
@@ -65,6 +66,31 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
6566
a["egress.monzo.com/config-hash"] = configHash
6667
a["egress.monzo.com/admin-port"] = strconv.Itoa(int(adPort))
6768

69+
img := "envoyproxy/envoy-alpine:v1.16.5"
70+
if i, ok := os.LookupEnv("ENVOY_IMAGE"); ok {
71+
img = i
72+
}
73+
74+
var tolerations []corev1.Toleration
75+
tk, kok := os.LookupEnv("TAINT_TOLERATION_KEY")
76+
tv, vok := os.LookupEnv("TAINT_TOLERATION_VALUE")
77+
if kok && vok {
78+
tolerations = append(tolerations, corev1.Toleration{
79+
Key: tk,
80+
Value: tv,
81+
Effect: corev1.TaintEffectNoSchedule,
82+
})
83+
}
84+
85+
var nodeSelector map[string]string
86+
nk, kok := os.LookupEnv("NODE_SELECTOR_KEY")
87+
nv, vok := os.LookupEnv("NODE_SELECTOR_VALUE")
88+
if kok && vok {
89+
nodeSelector = map[string]string{
90+
nk: nv,
91+
}
92+
}
93+
6894
var resources corev1.ResourceRequirements
6995
if es.Spec.Resources != nil {
7096
resources = *es.Spec.Resources
@@ -105,10 +131,12 @@ func deployment(es *egressv1.ExternalService, configHash string) *appsv1.Deploym
105131
Annotations: a,
106132
},
107133
Spec: corev1.PodSpec{
134+
Tolerations: tolerations,
135+
NodeSelector: nodeSelector,
108136
Containers: []corev1.Container{
109137
{
110-
Name: "gateway",
111-
Image: "envoyproxy/envoy-alpine:v1.16.5",
138+
Name: "gateway",
139+
Image: img,
112140
ImagePullPolicy: corev1.PullIfNotPresent,
113141
Ports: deploymentPorts(es),
114142
VolumeMounts: []corev1.VolumeMount{

0 commit comments

Comments
 (0)
Please sign in to comment.