There's a very nice project for a self-hosted speedtest called 'librespeed' which can be used to host your own speedtest page. Since everything is moving to containers, it's a nice way to get familiar with Kubernetes and Docker (yml file at the end).
Requirements:
- A Kubernetes Cluster of any size or form
- Access to dockerhub
I'll be using the adolfintel/speedtest image for my deployment and have 2 replicas.
First, create a deployment
[archy@kube01 ~]$ kubectl create deployment --image adolfintel/speedtest speedtest-kubernetes
Change the replicas to 2
[archy@kube01 ~]$ kubectl edit deployment speedtest-kubernetes
...
replicas: 2
...
Next up, expose the deployment. I'm using a very basic Kubernetes setup, so there are no loadbalancers available. I'll be using the NodePort type to expose a port on all Kubernetes-Nodes.
[archy@kube01 ~]$ kubectl expose deployment speedtest-kubernetes --name=speedtest-kubernetes --port=80 --type=NodePort
Check the current services and check the random port
[archy@kube01 ~]$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 1h
speedtest-kubernetes NodePort 10.107.110.250 <none> 80:32445/TCP 5s
Currently, the port 32445 will be forwarded to the 'speedtest-kubernetes' service' Port 80, so your site should be available already but I don't want to have some random port assigned to it.
Specifying a port is possible by editing the service and changing the 'nodePort' value.
[archy@kube01 ~]$ kubectl edit service speedtest-kubernetes
...
- nodePort: 30080
...
Check the service again to see if everything has been overwritten
[archy@kube01 ~]$ kubectl get service speedtest-kubernetes
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
speedtest-kubernetes NodePort 10.107.110.250 <none> 80:30080/TCP 29s
There's however a faster way of deploying this using a definition written in yaml.
Here's the commands from above in yaml:
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: speedtest
labels:
app: speedtest
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: speedtest
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: speedtest
spec:
containers:
- name: speedtest
image: adolfintel/speedtest
imagePullPolicy: Always
resources:
requests:
cpu: "128m"
memory: "32Mi"
limits:
cpu: "512m"
memory: "128Mi"
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
---
apiVersion: v1
kind: Service
metadata:
labels:
app: speedtest
name: speedtest
namespace: default
spec:
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- nodePort: 30080
port: 80
protocol: TCP
targetPort: 80
selector:
app: speedtest
sessionAffinity: None
type: NodePort
Applying this file will create the deployment and service all in one go:
[archy@kube01 ~]$ kubectl apply -f speedtest.yml
The port is now available using port 30080 on all Kubernetes Nodes.
Feel free to comment and / or suggest a topic
Comments
Post a Comment