Installing Code-Server with Podman on AWS (PART 1)
This article was originally published on October 3, 2024, on https://www.borislam.com
Background
Code-server is an open-source project that enables developers to run Visual Studio Code (VS Code) on a remote server. This setup is particularly useful for developers who want to access their development environment from anywhere, using just a browser. Podman is a container management tool that is gaining popularity.
In this guide, we will walk you through the process of setting up code-server on an AWS EC2 instance using Podman. We will also cover some recommended steps for configuring AWS services like Application Load Balancer (ALB) and AWS Certificate Manager (ACM) for a production-ready setup.
Why Podman?
For this tutorial, I have chosen to use Ubuntu as the operating system and Podman as the container runtime. Here's why:
I chose Ubuntu Linux for this setup because it works well with Podman, which can be easily installed from the Ubuntu package repository. Amazon Linux is also a good option but installing Podman on it would be more complicated. If you decide to install Code-server on Amazon Linux, Docker would be a better choice
Possible Use Cases and Architecture
Code-server on AWS EC2 with Podman provides benefits for various use cases:
Installation Steps
1. Launch EC2 Instance
~ Name: AppServerPodman
~ AMI: Ubuntu Server (latest LTS version) (see figure below)
~ Instance type: t2.micro (or larger based on your needs - see figure below)
~ Key pair: Create or select existing
~ Create security group with:
- SSH (Port 22) from your IP
- Custom TCP (Port 8080) from ALB security group
~ Storage: Default (or increase based on needs)
2. Initial Setup on EC2
First, connect to the EC2 instance. Then, update the system and install Podman:
sudo apt-get update
sudo apt-get install -y podman
2. Directory Configuration
Create necessary directories for code-server:
mkdir -p ~/.config/code-server
mkdir -p ~/project
# Set proper permissions
chmod 755 ~/.config/code-server
chmod 755 ~/project
3. Create Configuration File
Create and configure the code-server config file (config.yaml) under your server directory:
bind-addr: 0.0.0.0:8080
auth: password
password: some_password
cert: false
4. Run Code-Server Container
Launch code-server using Podman:
podman run -d \
--user $(id -u):$(id -g) \
--name code-server \
-p 8080:8080 \
-v "$HOME/project:/home/coder/project:Z" \
-v "$HOME/.config/code-server:/home/coder/.config/code-server:Z" \
docker.io/codercom/code-server:latest
5. Set Up Systemd Service
Configure code-server to run as a systemd service:
mkdir -p ~/.config/systemd/user/
cd ~/.config/systemd/user
podman generate systemd --new --files --name code-server
podman stop code-server
systemctl --user daemon-reload
systemctl --user start container-code-server.service
# Enable service to start at boot
systemctl --user enable container-code-server.service
6. Acquire Certificate in ACM and DNS Setup (Recommended)
For production use, it's recommended to:
~ Click "Request Certificate"
~ Choose "Request public certificate
~ "Enter your domain name (e.g., code.example.com)
~ Choose "DNS validation"
~ Click "Request"
~ Add the CNAME record provided by ACM
~ Wait for certificate validation (can take up to 30 minutes)
Recommended by LinkedIn
7. Create ALB and Target Group
A. Create Target Group:
~ Go to EC2 Console > Target Groups
~ Click "Create target group"
~ Choose "Instances" as target type
~ Name: AppServerProtocol: HTTP
~ Port: 8080
~ VPC: Select your VPC
~ Path: /
~ Healthy threshold: 2
~ Unhealthy threshold: 2
~ Timeout: 5 seconds
~Interval: 30 seconds
~ Register your EC2 instance - AppServerPodman (which is your code-server)
B. Create Application Load Balancer:
~ Go to EC2 Console > Load Balancers
~ Click "Create load balancer"
~ Choose "Application Load Balancer"
~ Name: code-server-alb
~ Scheme: Internet-facing
~ IP address type: IPv4
~ VPC: Select your VPC
~ Select at least two public subnets
~ Allow HTTPS (443) from anywhere
~ Allow HTTP (80) from anywhere
~ HTTP (80): Action: Redirect to HTTPS
~ HTTPS (443):Protocol: HTTPS
- Select your ACM certificate
- Forward to AppServer target group
Important Notes
Testing
After setup, you can access code-server by:
Security Considerations
Troubleshooting
If you encounter issues:
Conclusion and Summary
Running code-server on AWS EC2 with Podman is a great solution for small teams of developers. It's cost-effective, scalable, and secure. However, keep in mind:
Overall, code-server on Podman and EC2 is a great choice for small teams of developers who need a flexible and secure development environment.
It would help to improve security too, or at least I think so. Having a development server reduces the surface for attackers and centralizes security scanning and patching. As containers depend on kernel features, having the virtualized hardware standardized instead of hardware per developer strengthens even more the standardization containers alone can achieve. Love it <3