Skip to content

Commit 19da0df

Browse files
authored
Merge pull request #455 from kubernetes-sigs/leverage-common-subnet-tags
Adopt the kubernetes.io/role/internal-elb and kubernetes.io/role/elb tags
2 parents abb6776 + 25f8027 commit 19da0df

File tree

11 files changed

+303
-183
lines changed

11 files changed

+303
-183
lines changed

docs/configuration.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A sample IAM policy, with the minimum permissions to run the controller, can be
1313

1414
By default, all ingress resources in your cluster are seen by the controller. However, only ingress resources that contain the [required annotations](https://github.com/kubernetes-sigs/aws-alb-ingress-controller/blob/master/docs/ingress-resources.md#required-annotations) will be satisfied by the ALB Ingress Controller.
1515

16-
You can further limit the ingresses your controller has access to. The options available are limiting the ingress class (`ingress.class`) or limiting the namespace watched (`--watch-namespace=`). Each approach is detailed below.
16+
You can further limit the ingresses your controller has access to. The options available are limiting the ingress class (`ingress.class`) or limiting the namespace watched (`--watch-namespace=`). Each approach is detailed below.
1717

1818
### Limiting Ingress Class
1919

@@ -40,8 +40,6 @@ metadata:
4040
namespace: echoserver
4141
annotations:
4242
alb.ingress.kubernetes.io/port: "8080,9000"
43-
alb.ingress.kubernetes.io/subnets: subnet-63bf6318,subnet-0b20aa62
44-
alb.ingress.kubernetes.io/security-groups: sg-1f84f776
4543
kubernetes.io/ingress.class: "alb"
4644
spec:
4745
...
@@ -76,5 +74,4 @@ metadata:
7674
name: alb-ingress-controller-internet-facing-ingresses
7775
```
7876

79-
8077
That ConfigMap is kept in `default` if unspecified, but can moved to another with the `ALB_CONTROLLER_RESTRICT_SCHEME_CONFIG_NAMESPACE` environment variable. This can also be passed to the command line via the `restrict-scheme-namespace` flag.

docs/ingress-resources.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ metadata:
1717
annotations:
1818
kubernetes.io/ingress.class: alb
1919
alb.ingress.kubernetes.io/scheme: internal
20-
alb.ingress.kubernetes.io/subnets: subnet-1234
21-
alb.ingress.kubernetes.io/security-groups: sg-1234
2220
labels:
2321
app: 2048-nginx-ingress
2422
spec:

docs/setup.md

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ An example policy with the minimum rights can be found at [examples/iam-policy.j
1818

1919
The controller determines subnets to deploy each ALB to based on an annotation or auto-detection.
2020

21-
- annotation: `alb.ingress.kubernetes.io/subnets` may be specified in each ingress resource with the subnet IDs or `Name` tags. This allows for flexibility in where ALBs land. This list of subnets must include 2 or more that exist in unique availability zones. See the [annotations documentation](ingress-resources.md#annotations) for more details.
21+
##### Via annotation
22+
`alb.ingress.kubernetes.io/subnets` may be specified in each ingress resource with the subnet IDs or `Name` tags. This allows for flexibility in where ALBs land. This list of subnets must include 2 or more that exist in unique availability zones. See the [annotations documentation](ingress-resources.md#annotations) for more details.
2223

23-
- auto-detection: When subnet annotations are not present, the controller will attempt to choose the best subnets for deploying the ALBs. It uses the following tag criteria to determine the subnets it should use.
24+
##### Via tags on the subnets
25+
When subnet annotations are not present, the controller will attempt to choose the best subnets for deploying the ALBs. It uses the following tag criteria to determine the subnets it should use.
2426

25-
- `kubernetes.io/cluster/$CLUSTER_NAME`=`shared` where `$CLUSTER_NAME` matches the `CLUSTER_NAME` environment variable from the `alb-ingress-controller.yaml` manifest.
27+
- `kubernetes.io/cluster/$CLUSTER_NAME` equal to `shared` or `owned`. `$CLUSTER_NAME` must match the `CLUSTER_NAME` environment variable on the controller.
2628

27-
- `kubernetes.io/role/alb-ingress`=` ` where the value is empty.
29+
And one of the following:
30+
31+
- `kubernetes.io/role/internal-elb: ""` For internal load balancers
32+
- `kubernetes.io/role/elb = ""` For internet-facing load balancers
2833

2934
### Security Group Selection
3035

3136
The controller determines if it should create and manage security groups or use existing ones in AWS based on the presence of an annotation. When `alb.ingress.kubernetes.io/security-groups` is present, the list of security groups is assigned to the ALB instance. When the annotation is not present, the controller will create a security group with appropriate ports allowing access to `0.0.0.0/0` and attached to the ALB. It will also create a security group for instances that allows all TCP traffic when the source is the security group created for the ALB.
3237

33-
## helm Deployments
38+
## Helm Deployments
3439

3540
You must have the [Helm App Registry plugin](https://coreos.com/apps) installed for these instructions to work.
3641

@@ -40,100 +45,98 @@ helm registry install quay.io/coreos/alb-ingress-controller-helm
4045

4146
## kubectl Deployments
4247

43-
1. Setup default-backend-service
48+
1. Setup default-backend-service
49+
50+
A default backend service is required for every ingress controller. The alb-ingress-controller does not make use of it, but will not be able to run the ingress libraries without it. To get around this, deploy a dummy default backend to the cluster. The following example will deploy one in `kube-system`; you may wish to adjust it.
4451

45-
A default backend service is required for every ingress controller. The alb-ingress-controller does not make use of it, but will not be able to run the ingress libraries without it. To get around this, deploy a dummy default backend to the cluster. The following example will deploy one in `kube-system`; you may wish to adjust it.
46-
47-
```
48-
$ kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/default-backend.yaml
49-
```
52+
```
53+
$ kubectl create -f https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/default-backend.yaml
54+
```
5055
51-
1. Configure the alb-ingress-controller manifest.
56+
1. Configure the alb-ingress-controller manifest.
5257
53-
A sample manifest can be found below.
58+
A sample manifest can be found below.
5459
55-
```
56-
$ wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/alb-ingress-controller.yaml
57-
```
60+
```
61+
$ wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/alb-ingress-controller.yaml
62+
```
5863
59-
At minimum, edit the following variables.
64+
At minimum, edit the following variables.
6065
6166
- `AWS_REGION`: region in AWS this cluster exists.
6267
63-
```yaml
64-
- name: AWS_REGION
65-
value: us-west-1
66-
```
68+
```yaml
69+
- name: AWS_REGION
70+
value: us-west-1
71+
```
6772
68-
- `CLUSTER_NAME`: name of the cluster. If doing auto-detection of subnets (described in prerequisites above) `CLUSTER_NAME` must match the AWS tags associated with the subnets you wish ALBs to be provisioned.
73+
- `CLUSTER_NAME`: name of the cluster. If doing auto-detection of subnets (described in prerequisites above) `CLUSTER_NAME` must match the AWS tags associated with the subnets you wish ALBs to be provisioned.
6974
70-
```yaml
71-
- name: CLUSTER_NAME
72-
value: devCluster
73-
```
75+
```yaml
76+
- name: CLUSTER_NAME
77+
value: devCluster
78+
```
7479
75-
1. Deploy the alb-ingress-controller manifest.
80+
1. Deploy the alb-ingress-controller manifest.
7681
77-
```
78-
$ kubectl apply -f alb-ingress-controller.yaml
79-
```
82+
```
83+
$ kubectl apply -f alb-ingress-controller.yaml
84+
```
8085
81-
1. Verify the deployment was successful and the controller started.
86+
1. Verify the deployment was successful and the controller started.
8287
83-
```bash
84-
$ kubectl logs -n kube-system \
85-
$(kubectl get po -n kube-system | \
86-
egrep -o alb-ingress[a-zA-Z0-9-]+) | \
87-
egrep -o '\[ALB-INGRESS.*$'
88-
```
88+
```bash
89+
$ kubectl logs -n kube-system \
90+
$(kubectl get po -n kube-system | \
91+
egrep -o alb-ingress[a-zA-Z0-9-]+) | \
92+
egrep -o '\[ALB-INGRESS.*$'
93+
```
8994
90-
Should display output similar to the following.
95+
Should display output similar to the following.
9196
92-
```
93-
[ALB-INGRESS] [controller] [INFO]: Log level read as "", defaulting to INFO. To change, set LOG_LEVEL environment variable to WARN, ERROR, or DEBUG.
94-
[ALB-INGRESS] [controller] [INFO]: Ingress class set to alb
95-
[ALB-INGRESS] [ingresses] [INFO]: Build up list of existing ingresses
96-
[ALB-INGRESS] [ingresses] [INFO]: Assembled 0 ingresses from existing AWS resources
97-
```
97+
```
98+
[ALB-INGRESS] [controller] [INFO]: Log level read as "", defaulting to INFO. To change, set LOG_LEVEL environment variable to WARN, ERROR, or DEBUG.
99+
[ALB-INGRESS] [controller] [INFO]: Ingress class set to alb
100+
[ALB-INGRESS] [ingresses] [INFO]: Build up list of existing ingresses
101+
[ALB-INGRESS] [ingresses] [INFO]: Assembled 0 ingresses from existing AWS resources
102+
```
98103
99104
## external-dns Deployment
100105
101106
[external-dns](https://github.com/kubernetes-incubator/external-dns) provisions DNS records based on the host information. This project will setup and manage records in Route 53 that point to controller deployed ALBs.
102107
108+
1. Ensure your instance has the correct IAM permission required for external-dns. See https://github.com/kubernetes-incubator/external-dns/blob/master/docs/tutorials/aws.md#iam-permissions.
103109
104-
1. Ensure your instance has the correct IAM permission required for external-dns. See https://github.com/kubernetes-incubator/external-dns/blob/master/docs/tutorials/aws.md#iam-permissions.
105-
106-
107-
1. Download external-dns to manage Route 53.
110+
1. Download external-dns to manage Route 53.
108111
109-
```bash
110-
$ wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/external-dns.yaml
111-
```
112+
```bash
113+
$ wget https://raw.githubusercontent.com/kubernetes-sigs/aws-alb-ingress-controller/master/examples/external-dns.yaml
114+
```
112115
113-
1. Edit the `--domain-filter` flag to include your hosted zone(s)
116+
1. Edit the `--domain-filter` flag to include your hosted zone(s)
114117
115-
The following example is for a hosted zone test-dns.com
118+
The following example is for a hosted zone test-dns.com
116119
117-
```yaml
118-
args:
119-
- --source=service
120-
- --source=ingress
121-
- --domain-filter=test-dns.com # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
122-
- --provider=aws
123-
- --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
124-
```
120+
```yaml
121+
args:
122+
- --source=service
123+
- --source=ingress
124+
- --domain-filter=test-dns.com # will make ExternalDNS see only the hosted zones matching provided domain, omit to process all available hosted zones
125+
- --provider=aws
126+
- --policy=upsert-only # would prevent ExternalDNS from deleting any records, omit to enable full synchronization
127+
```
125128
126-
1. Deploy external-dns
129+
1. Deploy external-dns
127130
128-
```
129-
$ kubectl apply -f external-dns.yaml
130-
```
131+
```
132+
$ kubectl apply -f external-dns.yaml
133+
```
131134
132-
1. Verify it deployed successfully.
135+
1. Verify it deployed successfully.
133136
134-
```
135-
$ kubectl logs -f -n kube-system $(kubectl get po -n kube-system | egrep -o 'external-dns[A-Za-z0-9-]+')
137+
```
138+
$ kubectl logs -f -n kube-system $(kubectl get po -n kube-system | egrep -o 'external-dns[A-Za-z0-9-]+')
136139
137-
time="2017-09-19T02:51:54Z" level=info msg="config: &{Master: KubeConfig: Sources:[service ingress] Namespace: FQDNTemplate: Compatibility: Provider:aws GoogleProject: DomainFilter:[] AzureConfigFile:/etc/kuberne tes/azure.json AzureResourceGroup: Policy:upsert-only Registry:txt TXTOwnerID:my-identifier TXTPrefix: Interval:1m0s Once:false DryRun:false LogFormat:text MetricsAddress::7979 Debug:false}"
138-
time="2017-09-19T02:51:54Z" level=info msg="Connected to cluster at https://10.3.0.1:443"
139-
```
140+
time="2017-09-19T02:51:54Z" level=info msg="config: &{Master: KubeConfig: Sources:[service ingress] Namespace: FQDNTemplate: Compatibility: Provider:aws GoogleProject: DomainFilter:[] AzureConfigFile:/etc/kuberne tes/azure.json AzureResourceGroup: Policy:upsert-only Registry:txt TXTOwnerID:my-identifier TXTPrefix: Interval:1m0s Once:false DryRun:false LogFormat:text MetricsAddress::7979 Debug:false}"
141+
time="2017-09-19T02:51:54Z" level=info msg="Connected to cluster at https://10.3.0.1:443"
142+
```

pkg/alb/lb/loadbalancer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type NewDesiredLoadBalancerOptions struct {
3838
IngressAnnotations *map[string]string
3939
CommonTags util.ELBv2Tags
4040
IngressRules []extensions.IngressRule
41+
Resources *albrgt.Resources
4142
GetServiceNodePort func(string, int32) (*int64, error)
4243
GetServiceAnnotations func(string, string) (*map[string]string, error)
4344
TargetsFunc func(*string, string, string, *int64) albelbv2.TargetDescriptions
@@ -126,6 +127,7 @@ func NewDesiredLoadBalancer(o *NewDesiredLoadBalancerOptions) (newLoadBalancer *
126127
GetServiceAnnotations: o.GetServiceAnnotations,
127128
AnnotationFactory: o.AnnotationFactory,
128129
TargetsFunc: o.TargetsFunc,
130+
Resources: o.Resources,
129131
})
130132

131133
if err != nil {

pkg/alb/tg/targetgroups.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ type NewDesiredTargetGroupsOptions struct {
122122
LoadBalancerID string
123123
ExistingTargetGroups TargetGroups
124124
AnnotationFactory annotations.AnnotationFactory
125+
Resources *albrgt.Resources
125126
IngressAnnotations *map[string]string
126127
ALBNamePrefix string
127128
Namespace string
@@ -151,6 +152,7 @@ func NewDesiredTargetGroups(o *NewDesiredTargetGroupsOptions) (TargetGroups, err
151152
Namespace: o.Namespace,
152153
ServiceName: path.Backend.ServiceName,
153154
GetServiceAnnotations: o.GetServiceAnnotations,
155+
Resources: o.Resources,
154156
})
155157
if err != nil {
156158
return output, err
@@ -196,6 +198,7 @@ type mergeAnnotationsOptions struct {
196198
Namespace string
197199
ServiceName string
198200
GetServiceAnnotations func(string, string) (*map[string]string, error)
201+
Resources *albrgt.Resources
199202
}
200203

201204
func mergeAnnotations(o *mergeAnnotationsOptions) (*annotations.Annotations, error) {
@@ -217,6 +220,7 @@ func mergeAnnotations(o *mergeAnnotationsOptions) (*annotations.Annotations, err
217220
Annotations: mergedAnnotations,
218221
Namespace: o.Namespace,
219222
ServiceName: o.ServiceName,
223+
Resources: o.Resources,
220224
})
221225

222226
if err != nil {

pkg/albingress/albingress.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type NewALBIngressFromIngressOptions struct {
6161
Recorder record.EventRecorder
6262
ConnectionIdleTimeout *int64
6363
AnnotationFactory annotations.AnnotationFactory
64+
Resources *albrgt.Resources
6465
}
6566

6667
// NewALBIngressFromIngress builds ALBIngress's based off of an Ingress object
@@ -99,6 +100,7 @@ func NewALBIngressFromIngress(o *NewALBIngressFromIngressOptions) *ALBIngress {
99100
Annotations: o.Ingress.Annotations,
100101
Namespace: o.Ingress.Namespace,
101102
IngressName: o.Ingress.Name,
103+
Resources: o.Resources,
102104
})
103105
if err != nil {
104106
msg := fmt.Sprintf("Error parsing annotations: %s", err.Error())
@@ -132,6 +134,7 @@ func NewALBIngressFromIngress(o *NewALBIngressFromIngressOptions) *ALBIngress {
132134
GetServiceAnnotations: o.GetServiceAnnotations,
133135
TargetsFunc: o.TargetsFunc,
134136
AnnotationFactory: o.AnnotationFactory,
137+
Resources: o.Resources,
135138
})
136139

137140
if err != nil {

pkg/albingress/albingresses.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type NewALBIngressesFromIngressesOptions struct {
2828
GetServiceAnnotations func(string, string) (*map[string]string, error)
2929
TargetsFunc func(*string, string, string, *int64) albelbv2.TargetDescriptions
3030
AnnotationFactory annotations.AnnotationFactory
31+
Resources *albrgt.Resources
3132
}
3233

3334
// NewALBIngressesFromIngresses returns a ALBIngresses created from the Kubernetes ingress state.
@@ -59,6 +60,7 @@ func NewALBIngressesFromIngresses(o *NewALBIngressesFromIngressesOptions) ALBIng
5960
TargetsFunc: o.TargetsFunc,
6061
Recorder: o.Recorder,
6162
AnnotationFactory: o.AnnotationFactory,
63+
Resources: o.Resources,
6264
})
6365

6466
// Add the new ALBIngress instance to the new ALBIngress list.
@@ -72,6 +74,7 @@ type AssembleIngressesFromAWSOptions struct {
7274
Recorder record.EventRecorder
7375
ClusterName string
7476
ALBNamePrefix string
77+
Resources *albrgt.Resources
7578
}
7679

7780
// AssembleIngressesFromAWS builds a list of existing ingresses from resources in AWS
@@ -80,26 +83,15 @@ func AssembleIngressesFromAWS(o *AssembleIngressesFromAWSOptions) ALBIngresses {
8083
logger.Infof("Building list of existing ALBs")
8184
t0 := time.Now()
8285

83-
// Grab all of the tags for our cluster resources
84-
resources, err := albrgt.RGTsvc.GetResources(&o.ClusterName)
85-
if err != nil {
86-
logger.Fatalf(err.Error())
87-
}
88-
logger.Debugf("Retrieved tag information on %v load balancers, %v target groups, %v listeners, and %v rules",
89-
len(resources.LoadBalancers),
90-
len(resources.TargetGroups),
91-
len(resources.Listeners),
92-
len(resources.ListenerRules))
93-
9486
// Fetch the list of load balancers
95-
loadBalancers, err := albelbv2.ELBV2svc.ClusterLoadBalancers(resources)
87+
loadBalancers, err := albelbv2.ELBV2svc.ClusterLoadBalancers(o.Resources)
9688
if err != nil {
9789
logger.Fatalf(err.Error())
9890
}
9991
logger.Infof("Fetching information on %d ALBs", len(loadBalancers))
10092

10193
// Fetch the list of target groups
102-
targetGroups, err := albelbv2.ELBV2svc.ClusterTargetGroups(resources)
94+
targetGroups, err := albelbv2.ELBV2svc.ClusterTargetGroups(o.Resources)
10395
if err != nil {
10496
logger.Fatalf(err.Error())
10597
}
@@ -109,7 +101,7 @@ func AssembleIngressesFromAWS(o *AssembleIngressesFromAWSOptions) ALBIngresses {
109101
LoadBalancers: loadBalancers,
110102
ALBNamePrefix: o.ALBNamePrefix,
111103
Recorder: o.Recorder,
112-
ResourceTags: resources,
104+
ResourceTags: o.Resources,
113105
TargetGroups: targetGroups,
114106
})
115107

0 commit comments

Comments
 (0)