Creating an Ingress
In this section, we will create an Ingress. Octavia, the OpenStack LoadBalancer service, is able to work as a backend for ingress provider.
For this tutorial, we will create two webservers, and use the Ingress to redirect traffic to them depending on URL path.
Firstly, let us create the two webservers
kind: Pod apiVersion: v1 metadata: name: apple-app labels: app: apple spec: containers: - name: apple-app image: hashicorp/http-echo args: - "-text=apple" --- kind: Service apiVersion: v1 metadata: name: apple-service spec: selector: app: apple ports: - port: 5678 # Default port for image type: NodePort
kind: Pod apiVersion: v1 metadata: name: banana-app labels: app: banana spec: containers: - name: banana-app image: hashicorp/http-echo args: - "-text=banana" --- kind: Service apiVersion: v1 metadata: name: banana-service spec: selector: app: banana ports: - port: 5678 # Default port for image type: NodePort
Secondly, create the Ingress.
apiVersion: networking.k8s.io/v1beta1 kind: Ingress metadata: name: basic-ingress annotations: kubernetes.io/ingress.class: "openstack" octavia.ingress.kubernetes.io/internal: "false" labels: ingress: basic-ingress spec: rules: - http: paths: - path: /apple backend: serviceName: apple-service servicePort: 5678 - path: /banana backend: serviceName: banana-service servicePort: 5678
Wait till the Ingress becomes ready. You can see the creation events by doing
kubectl describe ingress/basic-ingress
You can also the check the OpenStack Loadbalancer providing the backend to this ingress by doing
openstack loadbalancer list
When the Ingress has been created, you should be able to see an IP associated with it. For example:
$ kubectl get ingress/basic-ingress NAME HOSTS ADDRESS PORTS AGE basic-ingress * 18.104.22.168 80 14m
Verify the Ingress is redirecting to the correct Service
$ curl http://22.214.171.124/apple apple $ curl http://126.96.36.199/banana banana