You’ve been asked to introduce GitOps to a small fleet. The Argo CD quickstart drops a manifest into kubectl apply, you port-forward the UI, you log in as admin with the auto-generated password, and you sync your first Application. Two months later, the admin password is still the auto-generated one, every operator shares the admin account because dex was never wired up, port-forward is how people reach the UI (kubectl access equals cluster write), the TLS cert is self-signed, and k3s embedded etcd lives on the root filesystem next to runaway logs.
What’s happening
An Argo CD deployment that is actually production-ready needs more than kubectl apply -f install.yaml. The base layer (k3s here) needs deliberate datastore placement, kubelet eviction thresholds that match the disk, and the embedded service load balancer disabled in favour of a real ingress controller; Argo CD is installed via Helm so the values are reviewable in Git; ingress-nginx fronts argocd-server with cert-manager + Let’s Encrypt; OIDC SSO replaces the admin account for day-to-day, with admin rotated and stored as break-glass only; the argocd-rbac-cm ConfigMap maps SSO groups to roles; and the GitOps source repo is locked at the Git layer. The cluster is the control plane for everything else — its operational discipline is the audit’s first stop.
How to verify
k3s should be healthy and the Argo CD pods all Running:
kubectl -n argocd get pods
The ingress should answer with a real cert chain:
echo | openssl s_client -servername argocd.example.com -connect argocd.example.com:443 2>/dev/null \
| openssl x509 -noout -subject -issuer -dates
And argocd login should work over the public hostname, not via port-forward:
argocd login argocd.example.com --sso
If it only works with --port-forward-namespace argocd, the ingress isn’t wired — fix it before exposing the cluster to apps.
The fix
Save the script below as /root/setup-argocd-ubuntu22.sh, then run it. It runs on a fresh Ubuntu 22.04 VM: apt update, unattended-upgrades, sysctl/FD tuning, SSH hardening, k3s with traefik and servicelb disabled, Helm, ingress-nginx + cert-manager + ClusterIssuer for Let’s Encrypt, the Argo CD Helm chart with the admin password set from a generated bcrypt hash, an Ingress with TLS, an OIDC config pointer, an RBAC ConfigMap mapping the argocd-admins group to admin, and a wait loop for the LE cert before declaring success.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 Argo CD on k3s clean VM installer
### k3s single-node (HA optional via embedded etcd)
### ingress-nginx + cert-manager + Let's Encrypt
### Argo CD via Helm, admin password rotated at install
### OIDC SSO ready (Authelia/Keycloak/Okta etc.)
### No local backups; assumes VM-level backup of /var/lib/rancher/k3s
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${ARGOCD_DOMAIN:?Set ARGOCD_DOMAIN (e.g. argocd.example.com)}"
: "${LE_EMAIL:?Set LE_EMAIL}"
: "${OIDC_ISSUER:?Set OIDC_ISSUER (e.g. https://auth.example.com)}"
: "${OIDC_CLIENT_ID:?Set OIDC_CLIENT_ID}"
: "${OIDC_CLIENT_SECRET:?Set OIDC_CLIENT_SECRET}"
ARGOCD_CHART_VERSION="${ARGOCD_CHART_VERSION:-7.6.12}"
ARGOCD_ADMIN_PASSWORD="$(openssl rand -base64 24)"
echo
echo "========================================"
echo "Argo CD on k3s Ubuntu 22.04 Setup"
echo "Domain: ${ARGOCD_DOMAIN}"
echo "OIDC issuer: ${OIDC_ISSUER}"
echo "========================================"
echo
export DEBIAN_FRONTEND=noninteractive
echo "==> Updating base OS"
apt-get update
apt-get -y upgrade
apt-get -y install \
ca-certificates curl gnupg lsb-release \
vim chrony fail2ban unattended-upgrades \
iproute2 lsof tcpdump dnsutils tar gzip unzip jq apache2-utils
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying sysctl tuning"
cat > /etc/sysctl.d/99-argocd.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
fs.inotify.max_user_watches = 524288
fs.inotify.max_user_instances = 512
vm.max_map_count = 262144
SYSCTL
modprobe br_netfilter || true
modprobe tcp_bbr || true
echo br_netfilter > /etc/modules-load.d/br_netfilter.conf
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-argocd.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Hardening SSH"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Enabling unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Installing k3s (no traefik, no servicelb, write kubeconfig 644)"
curl -sfL https://get.k3s.io | sh -s - \
--disable traefik \
--disable servicelb \
--write-kubeconfig-mode 644 \
--kubelet-arg "eviction-hard=memory.available<200Mi,nodefs.available<10%" \
--kube-controller-manager-arg "node-monitor-grace-period=30s"
echo "==> Waiting for k3s API"
for i in {1..60}; do
if kubectl get nodes >/dev/null 2>&1; then
break
fi
sleep 2
done
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
echo "==> Installing kubectl alias and Helm"
ln -sf /usr/local/bin/k3s /usr/local/bin/kubectl 2>/dev/null || true
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash
echo "==> Installing ingress-nginx via Helm"
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo add jetstack https://charts.jetstack.io
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm upgrade --install ingress-nginx ingress-nginx/ingress-nginx \
--namespace ingress-nginx --create-namespace \
--set controller.service.type=LoadBalancer \
--set controller.kind=DaemonSet \
--set controller.hostNetwork=true \
--set controller.dnsPolicy=ClusterFirstWithHostNet \
--set controller.publishService.enabled=false \
--set controller.config.use-forwarded-headers=true \
--wait --timeout 5m
echo "==> Installing cert-manager"
helm upgrade --install cert-manager jetstack/cert-manager \
--namespace cert-manager --create-namespace \
--set crds.enabled=true \
--wait --timeout 5m
echo "==> Creating Let's Encrypt ClusterIssuer"
cat <<ISSUER | kubectl apply -f -
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: ${LE_EMAIL}
privateKeySecretRef:
name: letsencrypt-prod-account
solvers:
- http01:
ingress:
class: nginx
ISSUER
echo "==> Generating bcrypt hash for Argo CD admin"
ARGOCD_ADMIN_HASH="$(htpasswd -nbBC 10 "" "${ARGOCD_ADMIN_PASSWORD}" | tr -d ':\n' | sed 's/\$2y/\$2a/')"
echo "==> Writing Argo CD values.yaml"
install -d /etc/argocd
cat > /etc/argocd/values.yaml <<VALS
global:
domain: ${ARGOCD_DOMAIN}
configs:
params:
server.insecure: true # TLS is terminated at ingress-nginx
secret:
argocdServerAdminPassword: '${ARGOCD_ADMIN_HASH}'
argocdServerAdminPasswordMtime: '$(date -u +%FT%TZ)'
cm:
url: https://${ARGOCD_DOMAIN}
oidc.config: |
name: SSO
issuer: ${OIDC_ISSUER}
clientID: ${OIDC_CLIENT_ID}
clientSecret: \$oidc.clientSecret
requestedScopes:
- openid
- profile
- email
- groups
admin.enabled: 'true'
accounts.readonly: apiKey, login
timeout.reconciliation: 180s
statusbadge.enabled: 'true'
rbac:
policy.default: role:readonly
policy.csv: |
g, argocd-admins, role:admin
g, argocd-devs, role:readonly
server:
replicas: 1
ingress:
enabled: true
ingressClassName: nginx
hostname: ${ARGOCD_DOMAIN}
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/backend-protocol: HTTP
nginx.ingress.kubernetes.io/ssl-passthrough: 'false'
tls: true
extraTls:
- hosts:
- ${ARGOCD_DOMAIN}
secretName: argocd-server-tls
controller:
replicas: 1
resources:
requests: { cpu: 250m, memory: 512Mi }
limits: { cpu: 2, memory: 2Gi }
repoServer:
replicas: 1
applicationSet:
enabled: true
notifications:
enabled: true
VALS
cat > /etc/argocd/oidc-secret.yaml <<OIDC
apiVersion: v1
kind: Secret
metadata:
name: argocd-secret
namespace: argocd
labels:
app.kubernetes.io/name: argocd-secret
app.kubernetes.io/part-of: argocd
type: Opaque
stringData:
oidc.clientSecret: '${OIDC_CLIENT_SECRET}'
OIDC
echo "==> Creating argocd namespace and OIDC client secret"
kubectl create namespace argocd --dry-run=client -o yaml | kubectl apply -f -
kubectl -n argocd apply -f /etc/argocd/oidc-secret.yaml
echo "==> Installing Argo CD via Helm"
helm upgrade --install argocd argo/argo-cd \
--version "${ARGOCD_CHART_VERSION}" \
--namespace argocd \
-f /etc/argocd/values.yaml \
--wait --timeout 10m
echo "==> Waiting for ingress cert to issue"
for i in {1..60}; do
if kubectl -n argocd get secret argocd-server-tls >/dev/null 2>&1; then
break
fi
sleep 5
done
if ! kubectl -n argocd get secret argocd-server-tls >/dev/null 2>&1; then
echo "Let's Encrypt cert not issued yet; check kubectl describe certificate -n argocd"
kubectl -n argocd get certificate || true
fi
echo "==> Installing argocd CLI"
ARGOCD_CLI_VER="$(curl -fsSL https://api.github.com/repos/argoproj/argo-cd/releases/latest | jq -r .tag_name)"
curl -fsSL -o /usr/local/bin/argocd \
"https://github.com/argoproj/argo-cd/releases/download/${ARGOCD_CLI_VER}/argocd-linux-amd64"
chmod 755 /usr/local/bin/argocd
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "k3s and Argo CD:"
kubectl get nodes -o wide
echo
kubectl -n argocd get pods
echo
echo "Ingress and cert:"
kubectl -n argocd get ingress
kubectl -n argocd get certificate
echo
echo "Listeners on host:"
ss -lntp | grep -E ':(80|443|6443)\b' || true
echo
echo "Web UI:"
echo "https://${ARGOCD_DOMAIN}/"
echo
echo "Break-glass admin credentials (stored in secret argocd-secret):"
echo " user: admin"
echo " password: ${ARGOCD_ADMIN_PASSWORD}"
echo
echo "OIDC users in group 'argocd-admins' have admin role via RBAC ConfigMap."
echo "Rotate the admin password into your secrets manager and use SSO day-to-day."
Make it executable and run it:
chmod 700 /root/setup-argocd-ubuntu22.sh
ARGOCD_DOMAIN=argocd.example.com \
LE_EMAIL=ops@example.com \
OIDC_ISSUER=https://auth.example.com \
OIDC_CLIENT_ID=argocd \
OIDC_CLIENT_SECRET=... \
/root/setup-argocd-ubuntu22.sh
After the first Let’s Encrypt issuance, log in once with the printed admin password to confirm the path, then move to SSO and treat admin as break-glass. The OIDC group claim must be named groups for the RBAC ConfigMap to map argocd-admins. Host-level backups are out of scope: /var/lib/rancher/k3s/server/db and /var/lib/rancher/k3s/storage are the stateful paths, and the VM is assumed to have snapshot/backup at the cloud layer.
GitOps only works when the cluster behind it is owned end-to-end — see how Stack Harbor runs the platform layer in Managed Cloud Ops → or start a conversation.