Ambassador Pod in Kubernetes ??
Hamza Shaukat
Junior Devops Engineer | RHEL | Bash Scripting | AWS | CI/CD | GitLab | Jenkins | Terraform | Kubernetes | Prometheus | Grafana
What is an Ambassador Container?
The ambassador container is a common pattern in Kubernetes and distributed systems. It acts as a proxy to provide additional functionality without modifying the main application.
Key Features ??
An ambassador container is a sidecar container that runs alongside the main application container in the same Pod, handling:
Why Use an Ambassador Container? ??
1. Decoupling Application Logic from Networking ??
Example Configurations ??
Basic Nginx Ambassador Pod:
apiVersion: v1
kind: Pod
metadata:
name: ambassador-nginx
labels:
app: ambassador-pod
spec:
containers:
- name: nginx
image: nginx:stable
ports:
- containerPort: 80
Ambassador Service:
apiVersion: v1
kind: Service
metadata:
name: ambassador-service
spec:
selector:
app: ambassador-pod
ports:
- protocol: TCP
port: 8081
targetPort: 80
Ambassador Pod with HAProxy ??
领英推荐
apiVersion: v1
kind: Pod
metadata:
name: ambassador-pod
spec:
containers:
- name: main-container
image: radial/busyboxplus:curl
command: ["sh", "-c", "while true; do curl localhost:8080; sleep 5; done"]
- name: ambassador-container
image: haproxy:2.4
ports:
- containerPort: 8080
volumeMounts:
- name: haproxy-config
mountPath: /usr/local/etc/haproxy/haproxy.cfg
subPath: haproxy.cfg
volumes:
- name: haproxy-config
configMap:
name: haproxy-config
HAProxy ConfigMap ??
apiVersion: v1
kind: ConfigMap
metadata:
name: haproxy-config
data:
haproxy.cfg: |
frontend ambassador
bind *:8080
default_backend ambassador_service_svc
backend ambassador_service_svc
server svc ambassador-service:8081
Useful Commands ??
Check Services:
kubectl get svc
Apply Configuration:
kubectl apply -f <file.yaml>
View Resources:
kubectl get po,svc
Check Service Details:
kubectl describe svc ambassador-service
View Logs:
kubectl logs ambassador-pod -c main-container
View ConfigMaps:
kubectl get configmap