Kubernetes Deployment
Problem
Deploying and managing applications in Kubernetes clusters, including handling deployments, services, ingress, config maps, secrets, and performing rolling updates with zero downtime.
Solution
Xec provides native Kubernetes integration through its execution engine, enabling seamless deployment automation, pod management, and cluster operations using familiar TypeScript/JavaScript syntax.
Quick Example
// k8s-deploy.ts
import { $ } from '@xec-sh/core';
const namespace = 'production';
const image = 'registry.example.com/myapp:v1.2.3';
// Update deployment
await $`
kubectl set image deployment/myapp \
myapp=${image} \
--namespace=${namespace} \
--record
`;
// Wait for rollout
await $`
kubectl rollout status deployment/myapp \
--namespace=${namespace} \
--timeout=5m
`;
Complete Kubernetes Deployment Recipes
Configuration
# .xec/config.yaml
targets:
k8s-dev:
type: kubernetes
context: dev-cluster
namespace: development
k8s-staging:
type: kubernetes
context: staging-cluster
namespace: staging
k8s-prod:
type: kubernetes
context: prod-cluster
namespace: production
tasks:
k8s-deploy:
description: Deploy to Kubernetes
params:
- name: env
required: true
values: [dev, staging, production]
- name: version
required: true
- name: replicas
default: 3
command: xec run scripts/k8s-deploy.ts ${params.env} ${params.version} ${params.replicas}