All tools / Kubernetes examples
Apache HTTP Server on Kubernetes
Apache httpd serving a static site from a ConfigMap, with a Service and an Ingress with TLS from cert-manager.
apache.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: apache-site
namespace: default
data:
index.html: |
<!doctype html><title>It works</title><h1>www.example.com is served by Apache on Kubernetes</h1>
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache
namespace: default
labels:
app: apache
spec:
replicas: 2
selector:
matchLabels:
app: apache
template:
metadata:
labels:
app: apache
spec:
containers:
- name: httpd
image: httpd:2.4
ports:
- name: http
containerPort: 80
readinessProbe:
httpGet:
path: /
port: http
livenessProbe:
tcpSocket:
port: http
initialDelaySeconds: 10
resources:
requests:
cpu: 50m
memory: 64Mi
limits:
memory: 256Mi
volumeMounts:
- name: site
mountPath: /usr/local/apache2/htdocs/index.html
subPath: index.html
volumes:
- name: site
configMap:
name: apache-site
---
apiVersion: v1
kind: Service
metadata:
name: apache
namespace: default
spec:
selector:
app: apache
ports:
- name: http
port: 80
targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: apache
namespace: default
annotations:
cert-manager.io/cluster-issuer: letsencrypt
spec:
ingressClassName: nginx
tls:
- hosts: ["www.example.com"]
secretName: apache-tls
rules:
- host: www.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: apache
port:
name: http
How to use it
Commands
kubectl apply -f apache.yaml kubectl -n default get pods -w
- The Ingress assumes the NGINX Ingress Controller and a cert-manager ClusterIssuer named letsencrypt.
Prefer Docker Compose? See the Apache HTTP Server Docker Compose version.