Introduction
Deployment
Deploying Kipchak with Docker and Kubernetes.
Kipchak is designed for modern cloud environments. It is fully containerised and ready for deployment on Kubernetes.
Docker
The Kipchak starter project includes a Dockerfile that is optimized for production. It uses FrankenPHP as the base image, ensuring high performance out of the box.
Production Readiness
Please change the FROM line in your Dockerfile to the production PHP Image by removing -dev:
Change:
FROM 1x.ax/mamluk/php/8.5:franken-dev
to:
FROM 1x.ax/mamluk/php/8.5:franken
Kipchak Enterprise customers can use the hardened runtime image instead: a static FrankenPHP binary with no shell, no package manager and no root user, which runs on a read-only filesystem.
Building the Image
To build your production image:
docker build -t my-kipchak-api .
Running the Container
docker run -p 80:80 my-kipchak-api
Kubernetes
Kipchak is Kubernetes-ready. Here's an example manifest of how to deploy the starter project to Kubernetes. You'll just need to change the container image name to your own and container registry and the correct name for your registry secret and the correct environtment variables.
apiVersion: apps/v1
kind: Deployment
metadata:
name: kipchak-api
namespace: kipchak-namespace
spec:
replicas: 2
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
selector:
matchLabels:
app: kipchak-api
template:
metadata:
labels:
app: kipchak-api
annotations:
prometheus.io/scrape: "true"
prometheus.io/endpoint: "/metrics"
prometheus.io/port: "2019"
spec:
imagePullSecrets:
- name: your-registry-secret
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: kipchak-api
containers:
- name: kipchak-api
image: your-registry/kipchak-api:$COMMIT_TAG
env:
- name: MEMCACHED_HOST
value: "memcached"
- name: MEMCACHED_PORT
value: "11211"
livenessProbe:
httpGet:
path: /status
port: 80
initialDelaySeconds: 3
periodSeconds: 7
timeoutSeconds: 5
failureThreshold: 7
startupProbe:
httpGet:
path: /status
port: 80
periodSeconds: 3
failureThreshold: 3
resources:
requests:
cpu: "250m"
memory: 350Mi
limits:
cpu: "750m"
memory: 750Mi
ports:
- containerPort: 80
name: api
protocol: TCP
- containerPort: 2019
name: metrics
protocol: TCP
Port 2019 serves only Prometheus metrics, at /metrics. From starter 4.12, Caddy's administration API is off and a listener of its own answers on that port (see Metrics). If your Caddyfile still sets admin :2019, follow Upgrading before exposing the port.
Horizontal Pod Autoscaling (HPA)
Because Kipchak is lightweight and starts quickly, it works exceptionally well with Kubernetes HPA, allowing your API to scale based on CPU or memory usage.
Confirming a deploy
A deploy tool that reports success has shown only that the new image was accepted, not that the new containers answer on your hostname. From starter 4.14, an image can carry an identifier of its build and send it in an X-Build header on every response, error pages included. A deploy job then reads the header from the public hostname and fails unless it shows the build just deployed. The same header tells you which build answered when someone reports a fault.
Setting the value
Pass BUILD_REF as a build argument, for example the output of git describe:
docker build --build-arg BUILD_REF="$(git describe --tags)" -t my-kipchak-api .
The value may be 1 to 64 letters, digits, dots, hyphens, plus signs and underscores. A release tag such as v1.4.2, a git describe value such as v1.4.2-3-gabc1234def56, and a date tag with a commit such as 2026-11-17-11-35+6d43f2f7e494 are all accepted. The build fails for any other value, so that no quote, space or control character reaches the server configuration. This form needs starter 4.15; starter 4.14 accepts only the last one. An image built without the argument sends no X-Build header, so nothing changes until you pass it.
The starter's Dockerfile declares the argument and passes it to the server, and both Caddyfiles send the header only when it is set:
@build expression `{env.BUILD_REF} != ""`
header @build X-Build {env.BUILD_REF}
Keep both lines. A header line without the @build matcher sends an empty X-Build header from an image built without the argument. If your Dockerfile has several stages, declare ARG BUILD_REF in the last one.
Checking it after a deploy
After the deploy step, request a path that answers 200 and is not served from a cache, such as /status, until the header shows the expected value several times in a row:
expected="$(git describe --tags)" # the value passed as BUILD_REF
ok=0
for i in $(seq 1 60); do
seen=$(curl -fsS -o /dev/null -D - --max-time 10 "https://api.example.com/status" \
| tr -d '\r' | awk 'tolower($1)=="x-build:" {print $2}')
if [ "$seen" = "$expected" ]; then ok=$((ok + 1)); [ "$ok" -ge 3 ] && exit 0; else ok=0; fi
sleep 10
done
echo "api.example.com serves '${seen:-no X-Build}', expected '$expected'"
exit 1
Require at least as many consecutive matches as you run replicas, and never fewer than three, so that a response from a replica still running the old build restarts the count. If a cache sits in front of the API, check a path the cache does not store, or the check reads the cached response.
Notes
Kipchak follows best practices for containerised applications:
- Logs: Logs are sent to
stdoutandstderrfor easy collection by logging drivers. - Environment Variables: Configuration is primarily handled through environment variables.
- Health Checks: Built-in support for readiness and liveness probes for the starter API.