Introduction
Deployment
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.4:franken-dev
to:
FROM 1x.ax/mamluk/php/8.4:franken
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: aladhan-com-api
containers:
- name: aladhan-com-api
image: 1x.ax/islamic-network/api.aladhan.com:$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
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.
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.