Skip to main content

Kubernetes Deployment

Styx provides native Kubernetes support with custom resource definitions (CRDs) and production-ready deployment manifests.

Quick Start

Deploy Styx to your Kubernetes cluster:
kubectl apply -f k8s/deployment.yaml

Deployment Manifest

The standard deployment creates a 3-replica Styx cluster:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: styx
  labels:
    app: styx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: styx
  template:
    metadata:
      labels:
        app: styx
    spec:
      containers:
        - name: styx
          image: styx:latest
          ports:
            - containerPort: 8080
              name: http
          livenessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            initialDelaySeconds: 3
            periodSeconds: 5
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 256Mi

Service Configuration

Styx includes two service types:

Standard ClusterIP Service

apiVersion: v1
kind: Service
metadata:
  name: styx
  labels:
    app: styx
spec:
  type: ClusterIP
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
      name: http
  selector:
    app: styx

Headless Service for Direct Pod Access

apiVersion: v1
kind: Service
metadata:
  name: styx-headless
  labels:
    app: styx
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 8080
      targetPort: 8080
      protocol: TCP
      name: http
  selector:
    app: styx

Custom Resource Definition (CRD)

Styx provides a CRD for declarative cluster management:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: styxclusters.styx.io
spec:
  group: styx.io
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                replicas:
                  type: integer
                  minimum: 1
                  default: 3
                image:
                  type: string
                  default: "styx:latest"
                port:
                  type: integer
                  default: 8080
                resources:
                  type: object
                  properties:
                    cpu:
                      type: string
                      default: "100m"
                    memory:
                      type: string
                      default: "128Mi"
            status:
              type: object
              properties:
                ready:
                  type: boolean
                nodes:
                  type: integer
                phase:
                  type: string
  scope: Namespaced
  names:
    plural: styxclusters
    singular: styxcluster
    kind: StyxCluster
    shortNames:
      - styx

Install the CRD

kubectl apply -f k8s/crd.yaml

Create a StyxCluster Resource

apiVersion: styx.io/v1
kind: StyxCluster
metadata:
  name: my-styx-cluster
spec:
  replicas: 5
  image: styx:latest
  port: 8080
  resources:
    cpu: "200m"
    memory: "256Mi"
Apply the custom resource:
kubectl apply -f my-styx-cluster.yaml

RBAC Configuration

The operator requires proper permissions:
apiVersion: v1
kind: ServiceAccount
metadata:
  name: styx-operator
  namespace: styx-system

Scaling

kubectl scale deployment styx --replicas=5

Health Monitoring

Liveness Probe

  • Path: /health
  • Initial Delay: 5 seconds
  • Period: 10 seconds

Readiness Probe

  • Path: /health
  • Initial Delay: 3 seconds
  • Period: 5 seconds

Resource Management

Default Resource Allocation

  • CPU Request: 100m
  • Memory Request: 128Mi
  • CPU Limit: 500m
  • Memory Limit: 256Mi

Adjust Resources

kubectl set resources deployment styx \
  --requests=cpu=200m,memory=256Mi \
  --limits=cpu=1,memory=512Mi

Operations

kubectl get pods -l app=styx

High Availability

For production HA deployments:
  1. Run multiple replicas (minimum 3)
  2. Use pod anti-affinity to spread across nodes
  3. Configure pod disruption budgets
  4. Use the headless service for direct pod discovery
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: styx-pdb
spec:
  minAvailable: 2
  selector:
    matchLabels:
      app: styx

Troubleshooting

Check Pod Status

kubectl get pods -l app=styx -o wide

View Events

kubectl get events --sort-by='.lastTimestamp'

Exec into Pod

kubectl exec -it <pod-name> -- sh

Test Service Connectivity

kubectl run test --rm -it --image=alpine -- wget -qO- http://styx:8080/health

Build docs developers (and LLMs) love