Skip to content

Commit 5ba87c4

Browse files
Add k3s installation to base Packer image
Install k3s (lightweight Kubernetes) in base AMI without auto-starting. Services can be started manually when needed.
1 parent ca6bebb commit 5ba87c4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

packer/base/base.pkr.hcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ build {
9393
script = "install/install_docker.sh"
9494
}
9595

96+
# install k3s (disabled, not auto-started)
97+
provisioner "shell" {
98+
script = "install/install_k3s.sh"
99+
}
100+
96101
provisioner "shell" {
97102
inline = [
98103
"sudo apt install openjdk-8-jdk openjdk-8-dbg openjdk-11-jdk openjdk-11-dbg openjdk-17-jdk openjdk-17-dbg -y",

packer/base/install/install_k3s.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
# Install k3s on Ubuntu 22.04
6+
# k3s will be installed but NOT enabled or started automatically
7+
# Services can be started manually when needed
8+
9+
# Download and run k3s installer
10+
# Using the latest stable until something breaks horribly forcing me to pin versions.
11+
#
12+
# INSTALL_K3S_SKIP_ENABLE: Don't enable systemd services
13+
# INSTALL_K3S_SKIP_START: Don't start services after installation
14+
curl -sfL https://get.k3s.io | \
15+
INSTALL_K3S_SKIP_ENABLE=true \
16+
INSTALL_K3S_SKIP_START=true \
17+
sh -
18+
19+
# Create kubectl symlink for convenience
20+
sudo ln -sf /usr/local/bin/k3s /usr/local/bin/kubectl
21+
22+
# Create kubeconfig directory structure
23+
sudo mkdir -p /etc/rancher/k3s
24+
25+
# Set up permissions for k3s config directory
26+
sudo chmod 755 /etc/rancher/k3s
27+
28+
# Verify installation (just check binary exists, don't start service)
29+
k3s --version
30+
kubectl version --client
31+
32+
echo "k3s installation complete. Services are installed but NOT enabled."
33+
echo "To start k3s server: sudo systemctl start k3s"
34+
echo "To start k3s agent: sudo systemctl start k3s-agent"

0 commit comments

Comments
 (0)