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/v1 kind: Ingress metadata: name: basic-ingress annotations: kubernetes.io/ingress.class: "openstack" octavia.ingress.kubernetes.io/internal: "false" labels: ingress: basic-ingress spec: rules: - host: http: paths: - path: /apple pathType: Prefix backend: service: name: apple-service port: number: 5678 - path: /banana pathType: Prefix backend: service: name: banana-service port: number: 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 CLASS HOSTS ADDRESS PORTS AGE basic-ingress <none> * 126.96.36.199 80 25m
Verify the Ingress is redirecting to the correct Service
$ curl http://188.8.131.52/apple apple $ curl http://184.108.40.206/banana banana