Next we will set up an example workload which will create objects on the load-balancer. Create a file called cdk-f5-ingress-example.yaml
:
---
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: cdk-cats
name: cdk-cats
spec:
replicas: 1
selector:
matchLabels:
app: cdk-cats
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: cdk-cats
ima: pod
spec:
containers:
- image: calvinhartwell/cdk-cats:latest
imagePullPolicy: Always
name: cdk-cats
ports:
- containerPort: 80
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
timeoutSeconds: 30
resources: {}
restartPolicy: Always
serviceAccountName: ""
status: {}
---
apiVersion: v1
kind: Service
metadata:
name: cdk-cats
labels:
app: cdk-cats
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
protocol: TCP
selector:
app: cdk-cats
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: cdk-cats
namespace: default
annotations:
# Provide an IP address from the external VLAN on your BIG-IP device
virtual-server.f5.com/ip: "10.190.25.70"
# Specify the BIG-IP partition containing the virtual server
virtual-server.f5.com/partition: "k8s"
spec:
backend:
# The name of the Kubernetes Service you want to expose to external traffic
serviceName: cdk-cats
servicePort: 80
Essentially this yaml describes the deployment of a single container, service and ingress rule. The ingress rule has annotations added to it which are picked up by the F5 Big-IP Controller container and replicated to the load-balancer automatically. Note, because we are using nodeport, the service has been given the type ‘NodePort’. The most important part of this example is the ingress rule at the bottom.
The annotations section is used to inform the Big-IP controller to pick-up information regarding the ingress rule, such as the IP address, port, partition name, etc. A full list of annotations and further examples can be found in the F5 controller manual.
To deploy the workload, all we need to do is run the following command:
kubectl apply -f cdk-f5-ingress-example.yaml
This will cause Kubernetes to pull and run the container by creating a deployment:
kubectl get pods
The output should look like following:
NAME READY STATUS RESTARTS AGE
cdk-cats-9c58684c9-4fg59 1/1 Running 0 5m24s
k8s-bigip-ctlr-669d7fcfcc-wwb4k 1/1 Running 0 6m20s
It will also create the service and the ingress rule. You can tail the logs of your Big-IP Controller container logs:
kubectl logs -f k8s-bigip-ctlr-669d7fcfcc-wwb4k
You should see messages like this:
2019/12/17 15:13:32 [INFO] Starting: Version: 1.12.0, BuildInfo: n2050-623590021
2019/12/17 15:13:32 [INFO] ConfigWriter started: 0xc000288d80
2019/12/17 15:13:32 [INFO] Started config driver sub-process at pid: 12
2019/12/17 15:13:32 [INFO] NodePoller (0xc0001226c0) registering new listener: 0x11bfea0
2019/12/17 15:13:32 [INFO] NodePoller started: (0xc0001226c0)
2019/12/17 15:13:32 [INFO] Watching Ingress resources.
2019/12/17 15:13:32 [INFO] Watching ConfigMap resources.
2019/12/17 15:13:32 [INFO] Handling ConfigMap resource events.
2019/12/17 15:13:32 [INFO] Handling Ingress resource events.
2019/12/17 15:13:32 [INFO] Registered BigIP Metrics
2019/12/17 15:13:33 [WARNING] Overwriting existing entry for backend {ServiceName:cdk-cats ServicePort:80 Namespace:default}
2019/12/17 15:13:33 [INFO] Wrote 1 Virtual Server and 0 IApp configs
2019/12/17 15:13:34 [INFO] [2019-12-17 15:13:34,214 __main__ INFO] entering inotify loop to watch /tmp/k8s-bigip-ctlr.config870278581/config.json
2019/12/17 15:13:34 [INFO] [2019-12-17 15:13:34,654 f5_cccl.resource.resource INFO] Creating ApiPool: /k8s/ingress_default_cdk-cats
2019/12/17 15:13:34 [INFO] [2019-12-17 15:13:34,980 f5_cccl.resource.resource INFO] Creating ApiVirtualServer: /k8s/ingress_10-190-25-70_80
2019/12/17 15:14:02 [INFO] Wrote 1 Virtual Server and 0 IApp configs
This indicates that the Big-IP controller container has picked up the ingress rule and replicated onto the load-balancer.
We can check that by logging onto the F5 Load-Balancer interface and going to the virtual server list. Make sure your partition is set to k8s in the top-right hand corner, otherwise you may not be able to see the objects:
As you can see, the name (ingress_10-190-25-70_80) for the newly created Virtual Server has been generated based on the IP address specified as the virtual-server.f5.com/ip
annotation and the servicePort which has been set to 80. If you click into the virtual server you can check that the rule matches your specification.
The controller container has also created a pool list for us automatically. Using the GUI on the left-hand side, click the Pools tab and go to Pool List. You should see a newly created pool based on the name of your ingress rule: