Automate Kubernetes deployments from GitHub Actions. Build images, push to registry, and deploy to Kubernetes clusters automatically on every commit.
Create deployment and service YAML files.
mkdir k8s-deploy && cd k8s-deploymkdir -p k8scat > k8s/deployment.yaml << 'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-app
labels:
app: web-app
spec:
replicas: 3
selector:
matchLabels:
app: web-app
template:
metadata:
labels:
app: web-app
spec:
containers:
- name: web
image: username/web-app:latest
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: production
EOFcat > k8s/service.yaml << 'EOF'
apiVersion: v1
kind: Service
metadata:
name: web-app
spec:
type: LoadBalancer
selector:
app: web-app
ports:
- port: 80
targetPort: 3000
EOFls k8s/Standard Kubernetes manifests: Deployment (3 replicas) and LoadBalancer Service. Image will be updated by CI pipeline with actual commit tag.
Manifests created in k8s/ directory. Ready for kubectl apply and CI/CD automation.