Deploy Application to Kubernetes
This guide provides a step-by-step procedure for deploying or updating applications to the Kubernetes cluster using Helm Charts managed through Rancher.
Overview
Section titled “Overview”The deployment process consists of three main steps:
- Update application version and ContainerImageTags in the
.csprojfile - Update Helm Chart versions in the repository
- Deploy via Rancher by updating the Helm Chart in Apps
Prerequisites
Section titled “Prerequisites”Before beginning deployment:
- Access to the application source code repository
- Access to the Helm Chart repository
- Access to Rancher UI
- Understanding of semantic versioning (e.g., 1.2.3)
Phase 1 — Update Application Version
Section titled “Phase 1 — Update Application Version”Update the version number in your .NET application’s project file.
1.1 Locate the .csproj file
Section titled “1.1 Locate the .csproj file”Navigate to your application repository and find the project file (e.g., MyService.csproj).
1.2 Update version and ContainerImageTags properties
Section titled “1.2 Update version and ContainerImageTags properties”Edit the .csproj file and update version-related properties:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <ContainerRepository>stable/meter-control-api</ContainerRepository> <ContainerImageTags>1.17.0</ContainerImageTags> <OutputPath></OutputPath> <DocumentationFile>bin/MeterControlApi.xml</DocumentationFile> </PropertyGroup> <!-- ... rest of file ... --></Project>Update the following property:
<ContainerImageTags>— Docker image version tag (e.g., 1.17.0)
1.3 Commit and push changes
Section titled “1.3 Commit and push changes”git add MyService.csprojgit commit -m "Bump version to 1.2.3"git push origin main1.4 Verify CI/CD build
Section titled “1.4 Verify CI/CD build”If you have automated CI/CD:
- Wait for build pipeline to complete
- Verify Docker image is built with new version tag
- Confirm image is pushed to container registry
Phase 2 — Update Helm Chart
Section titled “Phase 2 — Update Helm Chart”Update the Helm Chart to reference the new application version.
2.1 Navigate to Helm Chart repository
Section titled “2.1 Navigate to Helm Chart repository”Clone or navigate to your Helm Chart repository:
cd /path/to/helm-charts-repogit pull origin main2.2 Update Chart.yaml
Section titled “2.2 Update Chart.yaml”Edit the Chart.yaml file in your application’s Helm Chart directory:
apiVersion: v2name: meter-control-apidescription: Meter Control API Charttype: applicationversion: 1.0.13appVersion: "1.17.0"Update:
version— Helm Chart version (increment when chart structure changes, e.g., 1.0.13 → 1.0.14)appVersion— Application version (must match<ContainerImageTags>from.csproj, e.g., “1.17.0”)
2.3 Commit and push Helm Chart changes
Section titled “2.3 Commit and push Helm Chart changes”git add Chart.yaml values.yamlgit commit -m "Update meter-control-api to version 1.17.0 (chart 1.0.13)"git push origin mainPhase 3 — Deploy via Rancher
Section titled “Phase 3 — Deploy via Rancher”Update the Helm Chart deployment through Rancher UI.
3.1 Access Rancher
Section titled “3.1 Access Rancher”- Navigate to Rancher UI (e.g.,
https://rancher.inma.kalmarenergi.se) - Log in with your credentials
- Select the target cluster
3.2 Navigate to Apps
Section titled “3.2 Navigate to Apps”- In the left sidebar, click Apps → Installed Apps
- Select the namespace where your app is deployed (e.g.,
production) - Locate your application in the list
3.3 Upgrade the Helm Chart
Section titled “3.3 Upgrade the Helm Chart”Option A: Upgrade from Rancher UI
Section titled “Option A: Upgrade from Rancher UI”- Find your application (e.g.,
my-service) - Click the ⋮ (three-dot menu) on the right
- Select Upgrade
- In the upgrade dialog:
- Chart Version: Update to the new Helm Chart version (e.g.,
1.5.0) - Values: Review and update any values if needed
- Verify the appVersion or image tag is correct
- Chart Version: Update to the new Helm Chart version (e.g.,
- Click Upgrade to start deployment
Option B: Upgrade via kubectl (alternative)
Section titled “Option B: Upgrade via kubectl (alternative)”If you prefer command-line deployment:
# Ensure you're in the right contextkubectl config use-context <cluster-name>
# Upgrade the releasehelm upgrade my-service ./my-service \ --namespace production \ --values values.yaml \ --wait \ --timeout 10m3.4 Monitor deployment
Section titled “3.4 Monitor deployment”In Rancher UI:
- Go to Workloads → Pods
- Filter by namespace and app name
- Watch for pods to transition:
- Terminating — Old pods shutting down
- ContainerCreating — New pods starting
- Running — New pods healthy
Expected sequence:
my-service-7d8f9c-xyz (old) → Terminatingmy-service-8e9a0d-abc (new) → ContainerCreating → Running3.5 Verify deployment
Section titled “3.5 Verify deployment”Check deployment status:
In Rancher UI:
- Apps → Installed Apps → verify app shows as Deployed
- Workloads → verify all pods are Running
- Service Discovery → verify services have healthy endpoints
Via kubectl:
# Check deployment statuskubectl get deployment my-service -n inma
# Check pod statuskubectl get pods -n inma -l app=my-service
# Check rollout statuskubectl rollout status deployment/my-service -n inma
# View recent eventskubectl get events -n inma --sort-by='.lastTimestamp' | grep my-serviceExpected output:
NAME READY UP-TO-DATE AVAILABLE AGEmy-service 2/2 2 2 5m3.6 Check application health
Section titled “3.6 Check application health”Verify the application is functioning correctly:
# Check pod logskubectl logs -n inma deployment/my-service --tail=50
# Check for errorskubectl logs -n inma deployment/my-service --tail=100 | grep -i errorTest application endpoints:
# Port-forward to test locally (if needed)kubectl port-forward -n inma svc/my-service 8080:80
# Or test via ingresscurl -I https://my-service.example.com/healthExpected health check response: 200 OK
Post-Deployment Verification
Section titled “Post-Deployment Verification”Verify version is deployed
Section titled “Verify version is deployed”Check that the new version is running:
# Check image version in podskubectl describe pod -n inma -l app=my-service | grep Image:
# Check labelskubectl get pods -n inma -l app=my-service -o yaml | grep -A 5 labelsMonitor application metrics
Section titled “Monitor application metrics”- Check application logs for errors
- Test critical user flows
- Monitor error rates and response times
Validate configuration
Section titled “Validate configuration”Ensure configuration is correct:
# Check ConfigMapskubectl get configmap -n inma | grep my-service
# Check Secretskubectl get secrets -n inma | grep my-service
# Verify environment variableskubectl exec -n inma deployment/my-service -- env | grep APP_Rollback Procedure
Section titled “Rollback Procedure”If issues are discovered after deployment:
Via Rancher UI
Section titled “Via Rancher UI”- Go to Apps → Installed Apps
- Find your application
- Click ⋮ → Rollback
- Select the previous revision
- Confirm rollback
Via kubectl/Helm
Section titled “Via kubectl/Helm”# View revision historyhelm history my-service -n inma
# Rollback to previous versionhelm rollback my-service -n inma
# Or rollback to specific revisionhelm rollback my-service 5 -n inmaVia kubectl rollout
Section titled “Via kubectl rollout”# Rollback deploymentkubectl rollout undo deployment/my-service -n inma
# Check rollback statuskubectl rollout status deployment/my-service -n inmaTroubleshooting
Section titled “Troubleshooting”Pods not starting
Section titled “Pods not starting”Check pod status and events:
kubectl describe pod <pod-name> -n inmakubectl get events -n inma --sort-by='.lastTimestamp'Common issues:
- Image pull errors (check registry access and image tag)
- Resource limits (insufficient CPU/memory)
- ConfigMap/Secret not found
- Health probe failures
ImagePullBackOff error
Section titled “ImagePullBackOff error”# Check image name and tagkubectl describe pod <pod-name> -n inma | grep Image
# Verify image exists in registryaz acr repository show-tags --name myregistry --repository my-serviceSolutions:
- Verify image tag matches
appVersionin Helm Chart - Check container registry credentials
- Ensure CI/CD pushed image successfully
CrashLoopBackOff
Section titled “CrashLoopBackOff”Application starting but crashing:
# Check application logskubectl logs <pod-name> -n inma --previous
# Check liveness/readiness probeskubectl describe pod <pod-name> -n inma | grep -A 5 LivenessCommon causes:
- Application configuration errors
- Missing environment variables
- Database connection failures
- Port conflicts
Helm upgrade fails
Section titled “Helm upgrade fails”# Check Helm release statushelm list -n inmahelm status my-service -n inma
# View upgrade historyhelm history my-service -n inmaIf upgrade is stuck:
# Force upgradehelm upgrade my-service ./my-service -n inma --force
# Or rollback and try againhelm rollback my-service -n inmaBest Practices
Section titled “Best Practices”Version management
Section titled “Version management”- Use semantic versioning consistently
- Tag Git commits with version numbers
- Keep versions synchronized between
.csproj,Chart.yaml, and container images - Document breaking changes in release notes
Deployment strategy
Section titled “Deployment strategy”- Test in staging first before production deployment
- Use rolling updates to minimize downtime
- Configure pod disruption budgets for critical apps
- Set appropriate health checks (liveness, readiness, startup)
Monitoring and validation
Section titled “Monitoring and validation”- Monitor during rollout — watch logs and metrics
- Automated health checks — use Kubernetes probes
- Smoke tests — run critical tests after deployment
- Alert on failures — configure monitoring alerts
Chart management
Section titled “Chart management”- Version control Helm Charts in Git
- Use Helm repository for chart distribution
- Document values with comments in
values.yaml - Keep chart structure clean — use subchart dependencies
Deployment Checklist
Section titled “Deployment Checklist”- Update
ContainerImageTagsproperty in.csprojfile - Commit and push application changes
- Verify CI/CD build completes successfully
- Update
Chart.yamlwith new chart and app versions - Update
values.yamlimage tag to match ContainerImageTags - Validate Helm Chart with lint and dry-run
- Commit and push Helm Chart changes
- Access Rancher UI
- Navigate to Apps → Installed Apps
- Upgrade Helm Chart to new version
- Monitor pod rollout in Rancher
- Verify all pods are running
- Check application logs for errors
- Test application endpoints
- Verify version deployed correctly
- Monitor application metrics
- Document deployment in changelog
- Notify team of successful deployment