Skip to content

Commit 7156080

Browse files
authored
Update docs and examples for Ingress and Service (#1125)
Update docs to reflect new schema for `load_balancer_ingress`.
1 parent 4641827 commit 7156080

File tree

4 files changed

+183
-24
lines changed

4 files changed

+183
-24
lines changed

website/docs/d/ingress.html.markdown

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ resource "aws_route53_record" "example" {
2424
name = "example"
2525
type = "CNAME"
2626
ttl = "300"
27-
records = [data.kubernetes_ingress.example.load_balancer_ingress.0.hostname]
27+
records = [data.kubernetes_ingress.example.status.0.load_balancer.0.ingress.0.hostname]
2828
}
2929
```
3030

@@ -94,11 +94,19 @@ The following arguments are supported:
9494

9595
## Attributes
9696

97-
* `load_balancer_ingress` - A list containing ingress points for the load-balancer
97+
### `status`
9898

99-
### `load_balancer_ingress`
99+
* `status` - Status is the current state of the Ingress. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
100100

101-
#### Attributes
101+
#### `load_balancer`
102+
103+
* LoadBalancer contains the current status of the load-balancer, if one is present.
104+
105+
##### `ingress`
106+
107+
* `ingress` - Ingress is a list containing ingress points for the load-balancer. Traffic intended for the service should be sent to these ingress points.
108+
109+
###### Attributes
102110

103-
* `ip` - IP which is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)
104-
* `hostname` - Hostname which is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)
111+
* `ip` - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers).
112+
* `hostname` - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers).

website/docs/d/service.html.markdown

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ data "kubernetes_service" "example" {
2020
}
2121
2222
resource "aws_route53_record" "example" {
23-
zone_id = "${data.aws_route53_zone.k8.zone_id}"
23+
zone_id = "data.aws_route53_zone.k8.zone_id"
2424
name = "example"
2525
type = "CNAME"
2626
ttl = "300"
27-
records = ["${data.kubernetes_service.example.load_balancer_ingress.0.hostname}"]
27+
records = [data.kubernetes_service.example.status.0.load_balancer.0.ingress.0.hostname]
2828
}
2929
```
3030

@@ -37,7 +37,6 @@ The following arguments are supported:
3737
## Attributes
3838

3939
* `spec` - Spec defines the behavior of a service. [Kubernetes reference](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#spec-and-status)
40-
* `load_balancer_ingress` - A list containing ingress points for the load-balancer (only valid if `type = "LoadBalancer"`)
4140

4241
## Nested Blocks
4342

@@ -81,9 +80,24 @@ The following arguments are supported:
8180
* `session_affinity` - Used to maintain session affinity. Supports `ClientIP` and `None`. Defaults to `None`. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/services#virtual-ips-and-service-proxies)
8281
* `type` - Determines how the service is exposed. Defaults to `ClusterIP`. Valid options are `ExternalName`, `ClusterIP`, `NodePort`, and `LoadBalancer`. `ExternalName` maps to the specified `external_name`. For more info see [Kubernetes reference](http://kubernetes.io/docs/user-guide/services#overview)
8382

84-
### `load_balancer_ingress`
8583

86-
#### Attributes
84+
## Attributes
85+
86+
### `status`
87+
88+
* `status` - Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
89+
90+
#### `load_balancer`
91+
92+
* LoadBalancer contains the current status of the load-balancer, if one is present.
93+
94+
##### `ingress`
95+
96+
* `ingress` - Ingress is a list containing ingress points for the load-balancer. Traffic intended for the service should be sent to these ingress points.
97+
98+
###### Attributes
99+
100+
* `ip` - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers).
101+
* `hostname` - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers).
102+
87103

88-
* `hostname` - Hostname which is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)
89-
* `ip` - IP which is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)

website/docs/r/ingress.html.markdown

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,59 @@ resource "kubernetes_pod" "example2" {
9393
}
9494
```
9595

96+
## Example using Nginx ingress controller
97+
98+
```
99+
resource "kubernetes_service" "example" {
100+
metadata {
101+
name = "ingress-service"
102+
}
103+
spec {
104+
port {
105+
port = 80
106+
target_port = 80
107+
protocol = "TCP"
108+
}
109+
type = "NodePort"
110+
}
111+
}
112+
113+
resource "kubernetes_ingress" "example" {
114+
wait_for_load_balancer = true
115+
metadata {
116+
name = "example"
117+
annotations = {
118+
"kubernetes.io/ingress.class" = "nginx"
119+
}
120+
}
121+
spec {
122+
rule {
123+
http {
124+
path {
125+
path = "/*"
126+
backend {
127+
service_name = kubernetes_service.example.metadata.0.name
128+
service_port = 80
129+
}
130+
}
131+
}
132+
}
133+
}
134+
}
135+
136+
# Display load balancer hostname (typically present in AWS)
137+
output "load_balancer_hostname" {
138+
value = kubernetes_ingress.example.status.0.load_balancer.0.ingress.0.hostname
139+
}
140+
141+
# Display load balancer IP (typically present in GCP, or using Nginx ingress controller)
142+
output "load_balancer_ip" {
143+
value = kubernetes_ingress.example.status.0.load_balancer.0.ingress.0.ip
144+
}
145+
```
146+
147+
148+
96149
## Argument Reference
97150

98151
The following arguments are supported:
@@ -167,14 +220,23 @@ The following arguments are supported:
167220

168221
## Attributes
169222

170-
* `load_balancer_ingress` - A list containing ingress points for the load-balancer
223+
### `status`
171224

172-
### `load_balancer_ingress`
225+
* `status` - Status is the current state of the Ingress. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
173226

174-
#### Attributes
227+
#### `load_balancer`
228+
229+
* LoadBalancer contains the current status of the load-balancer, if one is present.
230+
231+
##### `ingress`
232+
233+
* `ingress` - Ingress is a list containing ingress points for the load-balancer. Traffic intended for the service should be sent to these ingress points.
234+
235+
###### Attributes
236+
237+
* `ip` - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers).
238+
* `hostname` - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers).
175239

176-
* `ip` - IP which is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)
177-
* `hostname` - Hostname which is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)
178240

179241
## Import
180242

website/docs/r/service.html.markdown

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ resource "kubernetes_service" "example" {
1919
}
2020
spec {
2121
selector = {
22-
app = "${kubernetes_pod.example.metadata.0.labels.app}"
22+
app = kubernetes_pod.example.metadata.0.labels.app
2323
}
2424
session_affinity = "ClientIP"
2525
port {
@@ -48,6 +48,73 @@ resource "kubernetes_pod" "example" {
4848
}
4949
```
5050

51+
## Example using AWS load balancer
52+
53+
```
54+
variable "cluster_name" {
55+
type = string
56+
}
57+
58+
data "aws_eks_cluster" "example" {
59+
name = var.cluster_name
60+
}
61+
62+
data "aws_eks_cluster_auth" "example" {
63+
name = var.cluster_name
64+
}
65+
66+
provider "aws" {
67+
region = "us-west-1"
68+
}
69+
70+
provider "kubernetes" {
71+
host = data.aws_eks_cluster.example.endpoint
72+
cluster_ca_certificate = base64decode(data.aws_eks_cluster.example.certificate_authority[0].data)
73+
exec {
74+
api_version = "client.authentication.k8s.io/v1alpha1"
75+
args = ["eks", "get-token", "--cluster-name", var.cluster_name]
76+
command = "aws"
77+
}
78+
}
79+
80+
resource "kubernetes_service" "example" {
81+
metadata {
82+
name = "example"
83+
}
84+
spec {
85+
port {
86+
port = 8080
87+
target_port = 80
88+
}
89+
type = "LoadBalancer"
90+
}
91+
}
92+
93+
# Create a local variable for the load balancer name.
94+
locals {
95+
lb_name = split("-", split(".", kubernetes_service.example.status.0.load_balancer.0.ingress.0.hostname).0).0
96+
}
97+
98+
# Read information about the load balancer using the AWS provider.
99+
data "aws_elb" "example" {
100+
name = local.lb_name
101+
}
102+
103+
output "load_balancer_name" {
104+
value = local.lb_name
105+
}
106+
107+
output "load_balancer_hostname" {
108+
value = kubernetes_service.example.status.0.load_balancer.0.ingress.0.hostname
109+
}
110+
111+
output "load_balancer_info" {
112+
value = data.aws_elb.example
113+
}
114+
```
115+
116+
117+
51118
## Argument Reference
52119

53120
The following arguments are supported:
@@ -110,14 +177,22 @@ The following arguments are supported:
110177

111178
## Attributes
112179

113-
* `load_balancer_ingress` - A list containing ingress points for the load-balancer (only valid if `type = "LoadBalancer"`)
180+
### `status`
114181

115-
### `load_balancer_ingress`
182+
* `status` - Most recently observed status of the service. Populated by the system. Read-only. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status
116183

117-
#### Attributes
184+
#### `load_balancer`
185+
186+
* LoadBalancer contains the current status of the load-balancer, if one is present.
187+
188+
##### `ingress`
189+
190+
* `ingress` - Ingress is a list containing ingress points for the load-balancer. Traffic intended for the service should be sent to these ingress points.
191+
192+
###### Attributes
118193

119-
* `ip` - IP which is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)
120-
* `hostname` - Hostname which is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)
194+
* `ip` - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers).
195+
* `hostname` - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers).
121196

122197
## Import
123198

0 commit comments

Comments
 (0)