These notes will help you setup Squid Proxy (Wikipedia).
1. Why Use a Proxy Inside a Pod?
A proxy acts as an intermediary between clients and servers. Running a proxy inside a Kubernetes pod lets you:
- π Enforce security policies (e.g., block certain domains, allowlist services).
- π Improve performance with caching.
- π Control outbound internet access (great for enterprise environments).
- π Monitor and log all outgoing traffic.
Now, letβs deploy Squid Proxy inside a pod!
2. Deploying a Squid Proxy in Kubernetes
Step 1: Create a ConfigMap for Squid Configuration
|
|
This Squid configuration:
- Listens on port
3128
- Denies caching (for security)
- Allows traffic only to
example.com
andtrusted.com
- Denies all other requests
Step 2: Deploy Squid Proxy as a Pod
|
|
Step 3: Expose the Proxy Service
|
|
Deploy everything:
|
|
Your Squid Proxy is now running inside a pod! π
3. Using Squid Proxy Inside Your Kubernetes Cluster
Configure Pods to Use the Proxy
Update your podβs environment variables:
|
|
This ensures all outbound traffic goes through Squid.
Test the Proxy
Exec into a pod:
|
|
Run a request:
|
|
If example.com
loads, Squid is working! π
4. Comparing Squid with Other Proxies
Proxy | Best For | Caching | Load Balancing | Security |
---|---|---|---|---|
Squid | Web filtering, caching | β Yes | β No | β Yes |
NGINX | Reverse proxy, API gateway | β Yes | β Yes | β Yes |
HAProxy | Load balancing | β No | β Yes | β Yes |
Traefik | Kubernetes-native proxy | β Yes | β Yes | β Yes |
When to Use Each Proxy
- Use Squid if you need web filtering and security.
- Use NGINX for reverse proxy and API gateway functions.
- Use HAProxy if you need high-performance load balancing.
- Use Traefik if you need dynamic Kubernetes-native routing.
5. Advanced Squid Configurations
Blocking Websites
Modify your squid.conf:
|
|
Restart Squid:
|
|
Now, requests to facebook.com
and youtube.com
will be blocked! π«
Enabling Logging
Squid logs all traffic by default, but you can store logs persistently:
|
|
Mount a persistent volume:
|
|
Now, logs will persist inside the pod.
6. Securing Squid with Authentication
You can require users to authenticate before using Squid:
Step 1: Install Authentication Package
Modify the deployment:
|
|
Step 2: Configure Squid for Authentication
Modify squid.conf
:
|
|
Step 3: Create Users
Exec into the Squid pod:
|
|
Create a user:
|
|
Restart Squid:
|
|
Now, users must log in before using the proxy! π
Final Thoughts
Squid Proxy is a powerful tool for controlling outbound network traffic in Kubernetes.
Key Takeaways
β
Squid Proxy helps control outbound traffic in a cluster.
β
You can block websites, cache requests, and enforce security policies.
β
Other proxies like NGINX, HAProxy, and Traefik have different use cases.
β
You can secure Squid with authentication.
If you need network control inside a pod, Squid is a great choice! π