CloudWiki
Resource

Ingress

Kubernetes
Kubernetes
Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend. An Ingress can be configured to give services externally-reachable urls, load balance traffic, terminate SSL, offer name based virtual hosting etc.
Terraform Name
terraform
kubernetes_ingress
Ingress
attributes:

Nested Blocks

metadata

Arguments

  • annotations - (Optional) An unstructured key value map stored with the ingress that may be used to store arbitrary metadata.

Note

By default, the provider ignores any annotations whose key names end with kubernetes.io. This is necessary because such annotations can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such annotations in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info: http://kubernetes.io/docs/user-guide/annotations

Note

By default, the provider ignores any labels whose key names end with kubernetes.io. This is necessary because such labels can be mutated by server-side components and consequently cause a perpetual diff in the Terraform plan output. If you explicitly specify any such labels in the configuration template then Terraform will consider these as normal resource attributes and manage them as expected (while still avoiding the perpetual diff problem). For more info: http://kubernetes.io/docs/user-guide/labels

Attributes

spec

Arguments

  • backend - (Optional) Backend defines the referenced service endpoint to which the traffic will be forwarded. See backend block attributes below.
  • rule - (Optional) A list of host rules used to configure the Ingress. If unspecified, or no rule matches, all traffic is sent to the default backend. See rule block attributes below.
  • tls - (Optional) TLS configuration. Currently the Ingress only supports a single TLS port, 443. If multiple members of this list specify different hosts, they will be multiplexed on the same port according to the hostname specified through the SNI TLS extension, if the ingress controller fulfilling the ingress supports SNI. See tls block attributes below.
  • ingress_class_name - (Optional) The ingress class name references an IngressClass resource that contains additional configuration including the name of the controller that should implement the class.

backend

Arguments

  • service_name - (Optional) Specifies the name of the referenced service.
  • service_port - (Optional) Specifies the port of the referenced service.

rule

Arguments

  • host - (Optional) Host is the fully qualified domain name of a network host, as defined by RFC 3986. Note the following deviations from the \"host\" part of the URI as defined in the RFC: 1. IPs are not allowed. Currently an IngressRuleValue can only apply to the IP in the Spec of the parent Ingress. 2. The : delimiter is not respected because ports are not allowed. Currently the port of an Ingress is implicitly :80 for http and :443 for https. Both these may change in the future. Incoming requests are matched against the host before the IngressRuleValue. If the host is unspecified, the Ingress routes all traffic based on the specified IngressRuleValue.
  • http - (Required) http is a list of http selectors pointing to backends. In the example: http:///? -> backend where parts of the url correspond to RFC 3986, this resource will be used to match against everything after the last '/' and before the first '?' or '#'. See http block attributes below.

http

  • path - (Required) Path array of path regex associated with a backend. Incoming urls matching the path are forwarded to the backend, see below for path block structure.

path

  • path - (Required) A string or an extended POSIX regular expression as defined by IEEE Std 1003.1, (i.e this follows the egrep/unix syntax, not the perl syntax) matched against the path of an incoming request. Currently it can contain characters disallowed from the conventional \"path\" part of a URL as defined by RFC 3986. Paths must begin with a '/'. If unspecified, the path defaults to a catch all sending traffic to the backend.
  • backend - (Required) Backend defines the referenced service endpoint to which the traffic will be forwarded to.

tls

Arguments

  • hosts - (Optional) Hosts are a list of hosts included in the TLS certificate. The values in this list must match the name/s used in the tlsSecret. Defaults to the wildcard host setting for the loadbalancer controller fulfilling this Ingress, if left unspecified.
  • secret_name - (Optional) SecretName is the name of the secret used to terminate SSL traffic on 443. Field is left optional to allow SSL routing based on SNI hostname alone. If the SNI host in a listener conflicts with the \"Host\" header field used by an IngressRule, the SNI host is used for termination and value of the Host header is used for routing.

Attributes

status

load_balancer

  • LoadBalancer contains the current status of the load-balancer, if one is present.
ingress
  • ingress - Ingress is a list containing ingress points for the load-balancer. Traffic intended for the service should be sent to these ingress points.
Attributes
  • ip - IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers).
  • hostname - Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers).

Associating resources with a
Ingress
Resources do not "belong" to a
Ingress
Rather, one or more Security Groups are associated to a resource.
Create
Ingress
via Terraform:
The following HCL creates a minimal Ingress resource example
Syntax:

resource "kubernetes_ingress" "example_ingress" {
 metadata {
   name = "example-ingress"
 }

 spec {
   backend {
     service_name = "myapp-1"
     service_port = 8080
   }

   rule {
     http {
       path {
         backend {
           service_name = "myapp-1"
           service_port = 8080
         }

         path = "/app1/*"
       }

       path {
         backend {
           service_name = "myapp-2"
           service_port = 8080
         }

         path = "/app2/*"
       }
     }
   }

   tls {
     secret_name = "tls-secret"
   }
 }
}

resource "kubernetes_service_v1" "example" {
 metadata {
   name = "myapp-1"
 }
 spec {
   selector = {
     app = kubernetes_pod.example.metadata.0.labels.app
   }
   session_affinity = "ClientIP"
   port {
     port        = 8080
     target_port = 80
   }

   type = "NodePort"
 }
}

resource "kubernetes_service_v1" "example2" {
 metadata {
   name = "myapp-2"
 }
 spec {
   selector = {
     app = kubernetes_pod.example2.metadata.0.labels.app
   }
   session_affinity = "ClientIP"
   port {
     port        = 8080
     target_port = 80
   }

   type = "NodePort"
 }
}

resource "kubernetes_pod" "example" {
 metadata {
   name = "terraform-example"
   labels = {
     app = "myapp-1"
   }
 }

 spec {
   container {
     image = "nginx:1.7.9"
     name  = "example"

     port {
       container_port = 8080
     }
   }
 }
}

resource "kubernetes_pod" "example2" {
 metadata {
   name = "terraform-example2"
   labels = {
     app = "myapp-2"
   }
 }

 spec {
   container {
     image = "nginx:1.7.9"
     name  = "example"

     port {
       container_port = 8080
     }
   }
 }
}

Create
Ingress
via CLI:
Parameters:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: my-app-ingress
 annotations:
   nginx.ingress.kubernetes.io/rewrite-target: /
spec:
 rules:
 - host: my-app.example.com
   http:
     paths:
     - path: /api
       pathType: Prefix
       backend:
         service:
           name: my-app-api
           port:
             name: http
     - path: /
       pathType: Prefix
       backend:
         service:
           name: my-app-ui
           port:
             name: http

Example:

kubectl create -f ingress.yaml

aws cost
Costs
Direct Cost
Indirect Cost
No items found.
Best Practices for
Ingress

Categorized by Availability, Security & Compliance and Cost

Low
Access allowed from VPN
No items found.
Low
Auto Scaling Group not in use
No items found.
Medium
Connections towards DynamoDB should be via VPC endpoints
No items found.
Medium
Container in CrashLoopBackOff state
No items found.
Low
EC2 with GPU capabilities
No items found.
Medium
EC2 with high privileged policies
No items found.
Medium
ECS cluster delete alarm
No items found.
Critical
ECS task with Admin access (*:*)
Medium
ECS task with high privileged policies
No items found.
Critical
EKS cluster delete alarm
No items found.
Medium
ElastiCache cluster delete alarm
No items found.
Medium
Ensure Container liveness probe is configured
No items found.
Medium
Ensure ECS task definition has memory limit
No items found.
Critical
Ensure EMR cluster master nodes are not publicly accessible
No items found.
More from
Kubernetes