Recently I found a really cool project for running accessibility scans against websites, but heres the kicker, it generates a really snazzy report once it is complete.
Given my itch to automate everything, I decided to wrap it in some Kubernetes goodness.
The key Kubernetes components used for this implementation are:
- Replication Controller
- OPTIONAL: You could also add an Ingress instead of my hardcoded “nodePort” declaration in the service.
For this post we will use the http://kubernetes.io site as our example target.
The following definition will:
- Create a batch job
- Scan the site
- Store the output into persistent storage for the next component to consume.
apiVersion: batch/v1 kind: Job metadata: name: a11y spec: template: metadata: name: a11y-generate spec: containers: - name: a11ym image: nickschuch/the-a11y-machine command: ["a11ym", "http://kubernetes.io", "-o", "/var/output"] volumeMounts: - name: report mountPath: "/var/output" volumes: - name: report hostPath: path: "/tmp/report" restartPolicy: OnFailure
# https://raw.githubusercontent.com/nickschuch/blog-kube-a11y/master/a11y-job.yaml $ kubectl create -f a11y-job.yaml
The following definition will consume our report, from the persistent storage, and expose it with Nginx.
apiVersion: v1 kind: ReplicationController metadata: name: a11y spec: replicas: 1 selector: app: a11y-frontend template: metadata: name: a11y-frontend labels: app: a11y-frontend spec: containers: - name: report-frontend image: nginx volumeMounts: - name: report mountPath: "/usr/share/nginx/html" volumes: - name: report hostPath: path: "/tmp/report"
# https://raw.githubusercontent.com/nickschuch/blog-kube-a11y/master/a11y-rc.yaml $ kubectl create -f a11y-rc.yaml
Finally, we now need to expose our report outside of the internal Kubernetes network. The following definition will make our report available on:
- Any node in the cluster
- Port 30061
apiVersion: v1 kind: Service metadata: name: a11y spec: selector: app: a11y-frontend ports: - name: http protocol: TCP port: 80 nodePort: 30061 type: LoadBalancer
# https://raw.githubusercontent.com/nickschuch/blog-kube-a11y/master/a11y-svc.yaml $ kubectl create -f a11y-svc.yaml
For the small amount of time it has taken me to put this together, I feel I have yielded some big results.
Below is the outcome from my quick scan of the https://kubernetes.io site.
Limitations in the current design
- Currently using image “nickschuch/the-a11y-machine”, soon this will become “liip/the-a11y-machine” and maintained under TheA11yMachine project (https://github.com/liip/TheA11yMachine/pull/16).
- Using a “hostPath” volume since running on a single node, will need to use a shared storage solution on a multi host cluster.