-
Initiate a Linux instance & Get it's
- Public IP address
- SSH credentials
-
Edit the IP address & SSH config in Kamal
deploy.yml
file. -
Test you SSH status with:
kamal lock status
-
If the above returns a non-zero error code, run the below:
eval `ssh-agent -s` ssh-add <path-to-your-key>.pem
-
Now test the SSH status again:
kamal lock status
This should now run successfully & exit with 0.
-
Generate a Classic Personal Access Token for
container:write
&container:read
for your Image Registry (DockerHub, GHCR, etc.) & add it to your environment variables (.env file). Also update the Registry details in thedeploy.yml
. -
If your SSH user is a non-root user, run the below command to add the user to the docker group:
sudo usermod -aG docker ${USER}
Note: The above needs to be ran on the Cloud VM. There is an open Issue on Kamal for the same here
Run the below for SSL config the first time
sudo mkdir -p /letsencrypt && sudo touch /letsencrypt/acme.json && sudo chmod 600 /letsencrypt/acme.json
Run this command to create the private bridge network used by kamal to reference containers on one instance
docker network create -d bridge private
-
Make sure you have docker buildx locally on your machine where you run the kamal CLI from!
-
Voila! You are all set to deploy your application to the cloud with Kamal! 🚀
kamal setup -c kamal/deploy.yml
This will setup the cloud VM with all the necessary tools & dependencies to run your application.
Make sure to run
kamal env push
before akamal deploy
to push the latest environment variables to the cloud VM.
-
If you run into an error such as:
failed to solve: cannot copy to non-directory:
Then simply run
pnpm clean
& try again. -
Make sure your Database accepts connection from the cloud VM. You can do this by adding the VM's IP address to the
Allowed Hosts
in your Database settings. -
If you get an error such as:
Lock failed: failed to acquire lock: lockfile already exists
Then simply run
kamal lock release -c kamal/deploy.yml
& try again. -
If you run into:
No config found
Then simply add the following at the end of the command:
-c kamal/deploy.yml
For further details, refer to the Kamal Documentation or reach out to us on our Discord
kamal rollback [git_commit_hash_to_rollback_to] -c kamal/deploy.yml
kamal app logs -c kamal/deploy.yml
- Install the CloudWatch Agent on the EC2 instance
wget https://amazoncloudwatch-agent.s3.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
-
Attach the IAM role of
CloudWatchFullAccessv2
to the EC2 instance -
Edit the CloudWatch Agent config file
sudo nano /opt/aws/amazon-cloudwatch-agent/bin/config.json
- Add the below config to the
config.json
file
{
"metrics": {
"metrics_collected": {
"mem": {
"measurement": ["mem_used_percent"],
"metrics_collection_interval": 60
}
},
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
}
}
}
- Fetch the config & start the CloudWatch Agent
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s
- Now go to Cloudwatch > Metrics > All Metrics > Custom Namespaces > CWAgent > InstanceId > {InstanceId} > Tick the Checkbox next to it > Graph above will be updated