Ingress¶
By now you should have created a Deployments that creates 1 or more pods and grouped by a Services to a single IP address.
An ingress exposes the service to the outside world. In addition, it provides routing by DNS names. You may have many pods that accept calls on HTTPS port 443. An ingress checks the URL that was used to get to the cluster. The ingress uses the URL to route the request to the appropriate server.
Typically, an AWS load balancer is pointing to a target group that contains all worker nodes. A DNS entry is created that would route traffic to our domain, for example: ** .dev.sandbox.simoncomputing.com*.
All traffic would be routed to the worker nodes, where an ingress controller will determine which service to route traffic to based on the complete URL address.
Here is an example YAML file describing an ingress:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tomcat-ing-dev
spec:
rules:
- host: tomcat.dev.sandbox.simoncomputing.com
http:
paths:
- path: /
backend:
serviceName: tomcat-svc-dev
servicePort: 8080
tls:
- hosts:
- dev.sandbox.simoncomputing.com
Here is an example of creating a deployment, service and ingress:
from k9.helper import (
set_default_namespace,
create_namespace,
create_secret,
)
# create namespace
set_default_namespace("ingress-unit-test")
create_namespace()
# create secret
secret_name = "tomcat-dev"
secrets = {
'url': 'https://some/url',
'password': 'My1SecretPassword',
'username': 'postgres'
}
create_secret(secret_name, secrets)
# create deployment
body = read_yaml('tomcat-deploy-dev.yml')
create_deployment(body)
# create service
body = read_yaml('tomcat-svc-dev.yml')
create_service(body)
# create ingress
body = read_yaml('../test/tomcat-ing-dev.yml')
create_ingress(body)
- k9.exts.list_ingress(namespace: Optional[str] = None)[source]¶
Lists ingresses in a namespace.
- Parameters
namespace – The namespace to search in. If not present, we use the default namespace.
- Returns
A list of every ingress in the namespace.
Example Output:
[ { 'name': 'kibana-ing', 'namespace': 'logging', 'hosts': [ 'kibana.np.sandbox.simoncomputing.com' ], 'address': [ '10.10.100.123', '10.10.101.145', '10.10.102.167' ], 'age': 123456789 } ]
- k9.exts.ingress_exists(name: str, namespace: Optional[str] = None)[source]¶
Checks existence of specified ingress.
- Parameters
name – Name of ingress to check.
namespace – Namespace to check, if None, check in default namespace.
- Returns
True if specified ingress exists.
- k9.exts.get_ingress(name: str, namespace: Optional[str] = None)[source]¶
Get details of specified ingress.
- Parameters
name – Name of ingress to get.
namespace – Namespace to get ingress from. If None, get from default namespace.
- Returns
- k9.exts.create_ingress(body: dict, namespace: Optional[str] = None)[source]¶
Creates an ingress point - which defines
- Parameters
body – Contains Ingress Definition - https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/ExtensionsV1beta1Ingress.md
namespace – Namespace to create ingress in. If None, use default namespace
- Returns
Example YAML File:
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: tomcat-ing-dev spec: rules: - host: tomcat.dev.sandbox.simoncomputing.com http: paths: - path: / backend: serviceName: tomcat-svc-dev servicePort: 8080 tls: - hosts: - dev.sandbox.simoncomputing.com
Example Call:
from k9.helper import read_yaml, create_ingress
body = read_yaml(‘../test/tomcat-ing-dev.yml’) create_ingress(body)