DEV Community

Leon Nunes
Leon Nunes

Posted on


Deploying squid in k3s on an RPI4B

What is k3s?

K3s is lightweight Kubernetes which is easy to install and is a single binary under 100 MB by Rancher. One can read more about it here.

Installing K3s?

K3s provides an installation script that is a convenient way to install it as a service on systemd or openrc based systems. This script is available at To install K3s using this method, just run:

curl -sfL | sh -
Enter fullscreen mode Exit fullscreen mode

After running this installation:

  • The K3s service will be configured to automatically restart after node reboots or if the process crashes or is killed
  • Additional utilities will be installed, including kubectl, crictl, ctr,, and
  • A kubeconfig file will be written to /etc/rancher/k3s/k3s.yaml and the kubectl installed by K3s will automatically use it

Why Squid?

Well I've been using Squid Proxy on my Raspberry Pi 2B for quite some time and I really wanted to get my hands dirty with Kubernetes.

What is Squid?

Taken from the ArchWiki Squid is a caching proxy for HTTP, HTTPS and FTP, providing extensive access controls.

Let's begin

I couldn't find a squid proxy container for my raspberry pi so I had to roll out my own Containerfile.

Now we can build this image with the version tag, this is important if you wish to rollout new changes to your application, having the latest flag is good having a version tag in your deployment is better, this is what I've observed and it's also a deployment strategy.

podman build squid-proxy:v1 .
Enter fullscreen mode Exit fullscreen mode

The problem now is how do I get Kubernetes to recognize this image that I've built? Since it's not on Docker Hub. I could, well deploy this to Docker Hub too, but, I didn't I instead spun up a docker registry container.

podman run -d -p 5000:5000 --restart on-failure --name registry registry:2
Enter fullscreen mode Exit fullscreen mode

Then I ran the following

podman build -t localhost:5000/squid-proxy:v1 .
podman push --tls-verify=false localhost:5000/squid-proxy:v1
Enter fullscreen mode Exit fullscreen mode

Note: The --tls-verify=false is required as we don't have TLS and the image push fails, since this is for learning purposes I've done it without TLS.

Deploying Squid to Kubernetes.

I'm still pretty new to Kubernetes, the basic unit of Kubernetes is a pod, a pod is something that can hold multiple containers within it. While I can deploy this within a pod directly I didn't, Kubernetes will do that for me via the deployment file.

If you want to get an overview of how Kubernetes works you can watch this video by @techworld_with_nana, Kubernetes Course

I decided to go this way, Create a LoadBalancer Service and a Deployment that would deploy SQUID to Kubernetes.

I have yet to find the docs that share all the fields for the YAML, but this is pretty much how the the image is deployed

        - name: log-dir
          emptyDir: {}
      - name: squid
        image: localhost:5000/squid-proxy:v2
          #imagePullPolicy: Never
        - containerPort: 3128
          - name: log-dir
            mountPath: "/var/log/squid"
      - name: tailer
        image: busybox
        - "/bin/sh"
        - "-c"
          - tail -F /var/log/squid/access.log
          - name: log-dir
            mountPath: "/var/log/squid"
Enter fullscreen mode Exit fullscreen mode

There is a volume folder that is common for both the containers since SQUID doesn't send logs to STDOUT

To run this you can simply do

$ kubectl apply -f squid-deployment.yml
deployment.apps/squid-dployment unchanged
service/squid-service unchanged
Enter fullscreen mode Exit fullscreen mode

This will create a Service and Deployment will create a pod

$ kubectl get service
$ kubectl get service
Enter fullscreen mode Exit fullscreen mode


$ kubectl get svc
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
kubernetes      ClusterIP       <none>           443/TCP          48d
squid-service   LoadBalancer   3128:32729/TCP   3d14h
Enter fullscreen mode Exit fullscreen mode

To get the deployments

$ kubectl get deploy
$ kubectl get deployment
Enter fullscreen mode Exit fullscreen mode

Which will show the following

squid-deployment   1/1     1            1           7d19h
Enter fullscreen mode Exit fullscreen mode

The last thing is to get the pods.

$ kubectl get po OR kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
squid-dployment-86bfc8d664-swwzj   2/2     Running   0          4d14h
svclb-squid-service-54nrc          1/1     Running   0          4d1h
Enter fullscreen mode Exit fullscreen mode

Once everything is up and running you can see the following in the curl headers.
Curl Image Headers

To see the logs and follow them you can do the following.

kubectl logs service/squid-service -c tailer -f
Enter fullscreen mode Exit fullscreen mode

That's all.

This is a simple and easy deployment using Kubernetes, if I've made any mistakes or you would like to suggest any changes please drop a comment below <3

Top comments (0)

50 CLI Tools You Can't Live Without

The top 50 must-have CLI tools, including some scripts to help you automate the installation and updating of these tools on various systems/distros.