Cloud Native 6 min read

How to Configure Kubernetes Pods to Use an HTTP Proxy

This guide explains why and how to set up HTTP/HTTPS proxy settings for Kubernetes pods in enterprise environments, covering use cases, two configuration methods (ConfigMap and direct environment variables), parameter details, testing procedures, and best practices for reliable outbound traffic.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Configure Kubernetes Pods to Use an HTTP Proxy

When managing a Kubernetes cluster in an enterprise network, you often need pods to access the Internet through an HTTP proxy due to security policies, network architecture, or external service requirements.

Use Cases

Outbound traffic control and auditing.

Enforcing network access policies by routing traffic through a designated egress point.

Isolating services with a proxy to strengthen internal security.

Accessing external APIs, such as the Discord API.

Configuration Methods

Method 1: Using a ConfigMap

Step 1: Create a ConfigMap

Create a ConfigMap named proxy-config that holds the proxy settings:

apiVersion: v1
kind: ConfigMap
metadata:
  name: proxy-config
data:
  http_proxy: http://<proxy-server>:<port>
  https_proxy: http://<proxy-server>:<port>
  no_proxy: .cluster.local,.svc,.my-company.com,127.0.0.1

Step 2: Reference the ConfigMap in the Pod definition

apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  containers:
  - name: example-container
    image: nginx
    envFrom:
    - configMapRef:
        name: proxy-config

Step 3: Verify the application uses the proxy

Ensure the pod’s applications read the HTTP_PROXY and HTTPS_PROXY environment variables (tools like curl and wget pick them up automatically, while some language‑specific HTTP clients may require explicit configuration).

Method 2: Set environment variables directly in the deployment

Step 1: Define env vars in the Pod/Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: example-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: example
  template:
    metadata:
      labels:
        app: example
    spec:
      containers:
      - name: example-container
        image: nginx
        env:
        - name: http_proxy
          value: http://<proxy-server>:<port>
        - name: https_proxy
          value: http://<proxy-server>:<port>
        - name: no_proxy
          value: .cluster.local,.svc,.my-company.com,127.0.0.1

Step 2: Apply changes and confirm proxy configuration

After applying the deployment, verify that your application or service reads and correctly uses these environment variables.

Parameter Explanation

http_proxy

/ https_proxy: specify the HTTP/HTTPS proxy server in the form http://<proxy-user>:<proxy-password>@<proxy-server>:<port>. no_proxy: list of addresses that bypass the proxy, typically including Kubernetes service discovery suffixes such as .cluster.local, .svc, and local network ranges.

Testing Proxy Settings

Enter the pod’s shell: kubectl exec -it example-pod -- /bin/sh Test the proxy with curl: curl -I 'https://discord.com' If a normal HTTP response is returned, the proxy is working; otherwise, check the proxy server configuration and network policies.

curl --location --request POST 'https://discord.com/api/v10/oauth2/token'

Conclusion

Properly configuring HTTP proxy settings for Kubernetes pods is a key step in meeting enterprise network requirements. Using a ConfigMap or setting environment variables directly provides control and flexibility for outbound traffic, but always test thoroughly before deployment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Cloud NativeProxyKubernetesConfigMap
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.