Kubernetes¶
Kubernetes (k8s) is an open-source container orchestration platform that automates the deployment, scaling, networking, and lifecycle management of containerised applications. Originally developed by Google, it is now maintained by the CNCF.
The core abstractions in Kubernetes are: Pod (the smallest deployable unit, one or more containers sharing a network namespace), Deployment (declarative specification of desired pod replicas), Service (stable network endpoint for a set of pods), Ingress (HTTP routing from outside the cluster), ConfigMap and Secret (configuration injection), and HorizontalPodAutoscaler (automatic scaling based on CPU/memory or custom metrics).
PHP applications are deployed on Kubernetes as Docker containers, typically using PHP-FPM with nginx or Caddy as the HTTP front-end, or as FrankenPHP/Swoole workers. The Kubernetes service layer provides built-in service discovery via DNS. Kubernetes is the most common runtime for PHP microservices at scale.
k8s is the numeronym for Kubernetes (8 letters between K and s).
# deployment.yaml — PHP-FPM application on Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: order-service
spec:
replicas: 3
selector:
matchLabels:
app: order-service
template:
metadata:
labels:
app: order-service
spec:
containers:
- name: php-fpm
image: myregistry/order-service:latest
ports:
- containerPort: 9000
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-secret
key: url
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: order-service
spec:
selector:
app: order-service
ports:
- port: 80
See also Kubernetes documentation.
Related : Docker, Container Orchestration, Microservice, Service Discovery, Load Balancer, Numeronym