Introduction
DeployHQ's Shell Servers provide a powerful way to deploy applications to AWS Elastic Container Service (ECS) or Elastic Kubernetes Service (EKS). This guide will walk you through the process of setting up and deploying containerised applications using DeployHQ's Shell Server functionality.
Prerequisites
- A DeployHQ account
- A AWS instance in which the images are going to be built used as bastion server
- AWS account with ECS or EKS cluster configured
- Docker images of your application
- AWS CLI configured with appropriate permissions
- kubectl (for EKS deployments)
Setting Up Shell Servers in DeployHQ
- Navigate to your DeployHQ project
- Go to Servers > Add New Server
- Select "Shell Server" as the server type
- Configure the following settings:
Protocol: SSH
Hostname: Your server hostname
Username: Your SSH username
Authentication: SSH Key or Password
Configuring Deployment Scripts
Required setup before in the instance
The AWS CLI must be installed and configured on the instance for this script to run.
For AWS ECS
- Create a deployment script in DeployHQ, for example
./deploy.sh
:
#!/bin/bash
# Set AWS region
export AWS_DEFAULT_REGION=your-aws-region
# Login to AWS ECR
aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin your-aws-account.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com
# Update ECS service
aws ecs update-service \
--cluster your-cluster-name \
--service your-service-name \
--force-new-deployment
For AWS EKS
- Create a deployment script, for example
./deploy.sh
:
#!/bin/bash
# Configure kubectl
aws eks update-kubeconfig --name your-cluster-name --region your-aws-region
# Apply Kubernetes manifests
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
# Roll out deployment
kubectl rollout restart deployment/your-deployment-name
Setting Up Deployment Configuration
1- Configure configuration files in DeployHQ: - Navigate to Project Settings > Config Files - Add necessary environment variables:
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_DEFAULT_REGION=your-region
2- Configure deployment settings:
# deployment-config.yml
build:
image: your-image-name:${BUILD_VERSION}
dockerfile: Dockerfile
deploy:
- script: deploy.sh
- notify: slack
Automating Deployments
Continuous Deployment Setup
1- Configure webhook triggers:
- Go to Project Settings > Webhooks
- Add GitHub/GitLab webhook URL
- Configure branch rules
2- Set up automatic deployments:
- Go to Project Settings > Automatic Deployments
- Configure in the branches that you want automatic deployments
Best Practices
1- Version Control
- Tag your Docker images with meaningful versions
- Use git tags for releases
2- Security
- Use IAM roles with minimal required permissions
- Rotate access keys regularly
- Store sensitive data in environment variables
3- Monitoring
- Set up deployment notifications
- Monitor deployment status
- Configure health checks
Example Deployment Workflow
# 1. Build and push Docker image
docker build -t your-app:${VERSION} .
docker tag your-app:${VERSION} your-ecr-repo:${VERSION}
docker push your-ecr-repo:${VERSION}
# 2. Update deployment manifests
sed -i "s/image: .*/image: your-ecr-repo:${VERSION}/" k8s/deployment.yaml
# 3. Deploy to ECS/EKS
./deploy.sh
# 4. Verify deployment
aws ecs describe-services --cluster your-cluster --services your-service
# or
kubectl get pods -n your-namespace
Troubleshooting
Common issues and solutions:
1- Authentication Failures
- Verify AWS credentials
- Check IAM permissions
- Ensure ECR login is successful
2- Deployment Failures
- Check deployment logs
- Verify resource availability
- Check container health status
3- Network Issues
- Verify VPC configuration
- Check security group rules
- Ensure proper subnet configuration
Conclusion
DeployHQ Shell Servers provide a flexible and powerful way to deploy applications to AWS ECS/EKS. By following this guide and best practices, you can set up automated, reliable deployments for your containerized applications.
Remember to:
- Keep your deployment scripts version controlled
- Regularly update your dependencies
- Monitor your deployments
- Follow security best practices
- Test your deployment process in a staging environment first
For more information, refer to the DeployHQ documentation and AWS documentation