Ingress
The ingress resource creates network traffic routing between local machine and cluster services. It enables exposing Kubernetes/Nomad cluster services to users or exposing local services to clusters for testing and development.
Use Cases
Section titled “Use Cases”As a lab author, you can use ingress resources to provide access to cluster services:
- Cluster Service Access: Expose web applications running in Kubernetes/Nomad clusters for users to interact with
- Development Workflows: Enable local-to-cluster connectivity for development and debugging scenarios
- Service Discovery Labs: Demonstrate how external traffic reaches cluster services through ingress controllers
Ingress resources bridge the gap between isolated cluster environments and user access, enabling realistic scenarios without complex networking setup.
HCL Syntax
Section titled “HCL Syntax”Basic Syntax
Section titled “Basic Syntax”resource "ingress" "web" { port = 8081
target { resource = resource.k8s_cluster.app port = 80
config = { service = "webapp" namespace = "default" } }}Full Syntax
Section titled “Full Syntax”resource "ingress" "admin" { port = 8444 expose_local = false
target { resource = resource.k8s_cluster.production port = 80 named_port = "http"
config = { service = "kubernetes-dashboard" namespace = "kubernetes-dashboard" } }}Fields
| Field | Type | Required | Description |
|---|---|---|---|
port | number | ✓ | Local port to expose the service on Constraintsport %v is reserved for internal use |
expose_ | bool | — | Expose a local service to the target |
target | block | ✓ | Target traffic destination |
Target
Target traffic destination
| Field | Type | Required | Description |
|---|---|---|---|
resource | referencecontainer, vm, k8s_cluster, nomad_cluster | ✓ | Target resource to route traffic to |
port | number | — | Target port |
named_ | string | — | Named port on the target |
config | map(string) | ✓ | Driver-specific configuration |
Computed Attributes
These attributes are set by the system and are read-only.
| Attribute | Type | Description |
|---|---|---|
ingress_id | string | ID of the created connector service |
local_address | string | Fully qualified URI for accessing from the local machine |
remote_address | string | Fully qualified URI for accessing in the remote machine |
Traffic Direction
Section titled “Traffic Direction”Cluster to Local (Default)
Section titled “Cluster to Local (Default)”expose_local = false - Expose cluster services to users:
resource "ingress" "app_access" { port = 8082
target { resource = resource.k8s_cluster.dev port = 80
config = { service = "webapp" namespace = "default" } }}Local to Cluster
Section titled “Local to Cluster”expose_local = true - Expose local services to cluster:
resource "ingress" "local_api" { port = 3000 expose_local = true
target { resource = resource.k8s_cluster.dev
config = { service = "local-dev-api" namespace = "default" } }}Examples
Section titled “Examples”Expose Kubernetes Dashboard
Section titled “Expose Kubernetes Dashboard”resource "ingress" "dashboard" { port = 8445
target { resource = resource.k8s_cluster.dev port = 443
config = { service = "kubernetes-dashboard" namespace = "kubernetes-dashboard" } }}Expose Web Application
Section titled “Expose Web Application”resource "ingress" "webapp" { port = 8083
target { resource = resource.k8s_cluster.app port = 80
config = { service = "nginx-service" namespace = "web" } }}Expose Database Admin Interface
Section titled “Expose Database Admin Interface”resource "ingress" "pgadmin" { port = 5050
target { resource = resource.k8s_cluster.app port = 80
config = { service = "pgadmin" namespace = "database" } }}Expose API with Named Port
Section titled “Expose API with Named Port”resource "ingress" "api_server" { port = 8000
target { resource = resource.k8s_cluster.production named_port = "api"
config = { service = "api-service" namespace = "api" } }}Multiple Service Exposure
Section titled “Multiple Service Exposure”resource "ingress" "frontend" { port = 3001
target { resource = resource.k8s_cluster.app port = 80
config = { service = "frontend-service" namespace = "web" } }}
resource "ingress" "backend" { port = 3002
target { resource = resource.k8s_cluster.app port = 8080
config = { service = "backend-service" namespace = "api" } }}
resource "ingress" "database" { port = 5432
target { resource = resource.k8s_cluster.app port = 5432
config = { service = "postgres" namespace = "database" } }}Usage in Service Resources
Section titled “Usage in Service Resources”Ingress resources are commonly referenced by service resources:
resource "service" "webapp" { target = resource.ingress.webapp port = 8083}
resource "layout" "app_layout" { column { instructions {} }
column { tab "app" { title = "Web Application" target = resource.service.webapp active = true } }}Best Practices
Section titled “Best Practices”- Port Organization: Use consistent port ranges for different service types
- Service Discovery: Use meaningful service names that match Kubernetes deployments
- Namespace Management: Organize services by namespace for clarity
- Security: Be cautious when exposing database or admin interfaces
- Documentation: Clearly document exposed services and their purposes
- Testing: Verify ingress connectivity before lab deployment
Common Issues
Section titled “Common Issues”Service Not Found
Section titled “Service Not Found”## Verify service exists in clusterkubectl get svc -n namespace-name
# Check ingress configurationresource "ingress" "app" { target { config = { service = "correct-service-name" # Must match kubectl output namespace = "correct-namespace" # Must match kubectl output } }}Port Conflicts
Section titled “Port Conflicts”# Ensure unique local portsresource "ingress" "app1" { port = 8090
target { resource = resource.k8s_cluster.dev port = 80
config = { service = "app1" namespace = "default" } }}
resource "ingress" "app2" { port = 8091 # Different port
target { resource = resource.k8s_cluster.dev port = 80
config = { service = "app2" namespace = "default" } }}Connection Issues
Section titled “Connection Issues”# Check cluster connectivitykubectl port-forward svc/service-name port:port -n namespace
# Verify ingress target matchesresource "ingress" "app" { port = 8080 # This is the local port users access
target { port = 80 # This must match the service port in Kubernetes }}