Skip to content

Instantly share code, notes, and snippets.

@ldx
Created October 21, 2020 21:28
Show Gist options
  • Save ldx/51064d09ffb161e1352f5d033b996cea to your computer and use it in GitHub Desktop.
Save ldx/51064d09ffb161e1352f5d033b996cea to your computer and use it in GitHub Desktop.
Install ssm-agent on EKS worker nodes via a Kubernetes daemonset.
# This is based on https://github.com/mumoshu/kube-ssm-agent, but installs ssm-agent directly at start time, instead of using a pre-built image.
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: ssm-agent
namespace: ssm-agent
labels:
k8s-app: ssm-agent
spec:
selector:
matchLabels:
name: ssm-agent
template:
metadata:
labels:
name: ssm-agent
spec:
hostNetwork: true
hostPID: true
containers:
- image: amazonlinux:2
name: ssm-agent
securityContext:
runAsUser: 0
privileged: true
command:
- bash
- -c
- yum update -y && yum install -y systemd curl tar sudo procps && yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm && amazon-ssm-agent start
volumeMounts:
# Allows systemctl to communicate with the systemd running on the host
- name: dbus
mountPath: /var/run/dbus
- name: run-systemd
mountPath: /run/systemd
# Allows to peek into systemd units that are baked into the official EKS AMI
- name: etc-systemd
mountPath: /etc/systemd
# This is needed in order to fetch logs NOT managed by journald
# journallog is stored only in memory by default, so we need
#
# If all you need is access to persistent journals, /var/log/journal/* would be enough
# FYI, the volatile log store /var/run/journal was empty on my nodes. Perhaps it isn't used in Amazon Linux 2 / EKS AMI?
# See https://askubuntu.com/a/1082910 for more background
- name: var-log
mountPath: /var/log
- name: var-run
mountPath: /var/run
- name: run
mountPath: /run
- name: usr-lib-systemd
mountPath: /usr/lib/systemd
- name: etc-machine-id
mountPath: /etc/machine-id
- name: etc-sudoers
mountPath: /etc/sudoers.d
volumes:
# for systemctl to systemd access
- name: dbus
hostPath:
path: /var/run/dbus
type: Directory
- name: run-systemd
hostPath:
path: /run/systemd
type: Directory
- name: etc-systemd
hostPath:
path: /etc/systemd
type: Directory
- name: var-log
hostPath:
path: /var/log
type: Directory
# mainly for dockerd access via /var/run/docker.sock
- name: var-run
hostPath:
path: /var/run
type: Directory
# var-run implies you also need this, because
# /var/run is a synmlink to /run
# sh-4.2$ ls -lah /var/run
# lrwxrwxrwx 1 root root 6 Nov 14 07:22 /var/run -> ../run
- name: run
hostPath:
path: /run
type: Directory
- name: usr-lib-systemd
hostPath:
path: /usr/lib/systemd
type: Directory
# Required by journalctl to locate the current boot.
# If omitted, journalctl is unable to locate host's current boot journal
- name: etc-machine-id
hostPath:
path: /etc/machine-id
type: File
# Avoid this error > ERROR [MessageGatewayService] Failed to add ssm-user to sudoers file: open /etc/sudoers.d/ssm-agent-users: no such file or directory
- name: etc-sudoers
hostPath:
path: /etc/sudoers.d
type: Directory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment