Skip to content

Latest commit

 

History

History
103 lines (76 loc) · 4.7 KB

File metadata and controls

103 lines (76 loc) · 4.7 KB

CD Tidbit — Basic Deployment (Rolling to Dev)

Deploy a public nginx container to a Kubernetes Dev environment using Harness CD with the Rolling strategy. This is the starting point for Harness CD: wire up a service, an environment, and an infrastructure definition, then run a Deploy stage that rolls out pods with zero downtime and rolls back automatically on failure.


How it works

Harness CD has three building blocks before you can deploy anything:

Building block What it answers This example
Service What are you deploying? nginx image + K8s manifests
Environment Where are you deploying? Dev (PreProduction)
Infrastructure Which cluster/namespace? KubernetesDirect → tidbit-0044

The pipeline wires these together in a single Deploy stage:

Pipeline: tidbit_cd_basic_deployment
└── Stage: Deploy to Dev
    ├── Service:        svc_tid0044       → nginx:stable + k8s manifests
    ├── Environment:    env_dev_tid0044   → PreProduction (Dev)
    ├── Infrastructure: infra_k8s_tid0044 → namespace tidbit-0044
    └── Execution:
        ├── K8sRollingDeploy    ← applies manifests, waits for pods Ready
        └── K8sRollingRollback  ← runs automatically on any failure

Rolling strategy means Harness replaces pods incrementally — old pods stay up until new ones are healthy, so there's no downtime. If anything goes wrong, the failure strategy triggers K8sRollingRollback (kubectl rollout undo) automatically.


Repo layout

.harness/
  pipeline.yaml        # 1 Deploy stage, Rolling strategy
  service.yaml         # nginx artifact + K8s manifest source
  environment.yaml     # PreProduction (Dev) environment
  infrastructure.yaml  # KubernetesDirect: connector + namespace
k8s/
  namespace.yaml       # creates the target namespace (must be applied first)
  deployment.yaml      # nginx Deployment (Go-templated)
  service.yaml         # ClusterIP Service (Go-templated)
  values.yaml          # image, namespace, replicas — rendered at deploy time

Prerequisites

  1. Harness account with Continuous Delivery enabled.
  2. Kubernetes Cluster connector pointing at a real cluster (delegate-backed). The delegate needs RBAC to create a namespace and a Deployment/Service. Confirm it tests green before running.
  3. DockerHub connector — anonymous auth is fine because nginx is a public image.
  4. Manifests uploaded to Harness. Two options:
    • File Store (easiest): Project Setup → File Store → upload the four files from k8s/ into a folder.
    • Git: fork this repo and point the service's manifest store at your fork's k8s/ folder.

Run it

  1. Fork or clone this repo.
  2. Upload manifests to the Harness File Store (or use Git as described above).
  3. Create connectors if you don't have them yet. Update every # REPLACE: line in the .harness/*.yaml files.
  4. Import entities in this order — Deployments > New > YAML, paste each file:
    • service.yamlenvironment.yamlinfrastructure.yamlpipeline.yaml
  5. Run the pipeline tidbit_cd_basic_deployment. No runtime inputs needed — the tag is pinned to stable.
  6. Watch the Rollout Deployment step: Harness renders the manifests, runs a dry run, applies them, and waits for steady state.

Verify the rollout

kubectl get ns tidbit-0044
kubectl -n tidbit-0044 get deploy,po,svc
kubectl -n tidbit-0044 rollout status deploy/basic-deployment-deployment
# Expected: deployment "basic-deployment-deployment" successfully rolled out

In the Harness UI, the Rollout Deployment step turns green and its Output tab shows the deployed image digest.


Troubleshooting

Symptom Likely cause Fix
namespaces "tidbit-0044" not found Harness doesn't auto-create namespaces Make sure namespace.yaml is listed first in the service manifest files and createNamespace: true in values.yaml
There are no eligible delegates available Connector can't reach a delegate Install or health-check a delegate; test the connector — it must be green
ImagePullBackOff Cluster can't pull the image Official images need the library/ prefix (library/nginx); check cluster egress to DockerHub
Rollout hangs then rolls back Pods can't schedule or fail readiness Lower replicas / resources.requests in values.yaml; inspect with kubectl -n tidbit-0044 describe po
Governance / OPA blocks the run A policy set is denying the pipeline Review Project Settings > Governance; a Deployment-type stage is unaffected by CI-only policies

Clean up

kubectl delete ns tidbit-0044