Skip to content

Instantly share code, notes, and snippets.

@Topher-the-Geek
Last active February 7, 2021 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Topher-the-Geek/730dcca1808a44247aa338f1a65f28bd to your computer and use it in GitHub Desktop.
Save Topher-the-Geek/730dcca1808a44247aa338f1a65f28bd to your computer and use it in GitHub Desktop.
PHP app to show HTTP headers when served through AWS ALB/EKS
# Simple PHP app served through AWS Application Load Balancer to Kubernetes cluster.
# Assumes you have setup a Kubernetes cluster with AWS Load Balancer Controller and External DNS
# https://kubernetes-sigs.github.io/aws-load-balancer-controller/latest/
# https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/aws.md
# https://github.com/kubernetes-sigs/external-dns/blob/master/docs/tutorials/alb-ingress.md
# There's a couple place holders near the bottom to be filled in.
apiVersion: v1
kind: ConfigMap
metadata:
name: view-headers
labels:
k8s-app: view-headers
data:
index.php: |
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
$headers = getallheaders();
foreach($headers as $key=>$val){
echo $key . ': ' . $val . '<br>';
}
?>
</body>
</html>
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: view-headers
spec:
selector:
matchLabels:
run: view-headers
replicas: 2
template:
metadata:
labels:
run: view-headers
spec:
containers:
- name: php
image: php:7.2-apache
ports:
- containerPort: 80
volumeMounts:
- name: view-headers
mountPath: /var/www/html/
volumes:
- name: view-headers
configMap:
name: view-headers
---
kind: Service
apiVersion: v1
metadata:
name: view-headers
labels:
run: view-headers
spec:
type: NodePort
selector:
run: view-headers
ports:
- port: 80
targetPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: view-headers
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/certificate-arn: <Your AWS CertificateManager Cert, or remove this line>
spec:
rules:
- host: view-headers.<Your Route53 Hosted Zone>
http:
paths:
- path: /*
backend:
serviceName: view-headers
servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment