Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Ubuntu 18.04 as source AMI #2

Merged
merged 3 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@ KUBERNETES_VERSION ?= 1.10.3

DATE ?= $(shell date +%Y-%m-%d)

# Defaults to Amazon Linux 2 LTS AMI
# * use the us-west-2 minimal hvm image
# https://aws.amazon.com/amazon-linux-2/release-notes/
SOURCE_AMI_ID ?= $(shell aws ec2 describe-images \
--output text \
--filters \
Name=owner-id,Values=137112412989 \
Name=owner-id,Values=099720109477 \
Name=virtualization-type,Values=hvm \
Name=root-device-type,Values=ebs \
Name=name,Values=amzn2-ami-minimal-hvm-* \
Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-* \
Name=architecture,Values=x86_64 \
Name=state,Values=available \
--query 'max_by(Images[], &CreationDate).ImageId')
Expand All @@ -24,7 +21,7 @@ AWS_DEFAULT_REGION = us-west-2
all: ami

validate:
packer validate eks-worker-al2.json
packer validate eks-worker-bionic.json

ami: validate
packer build -color=false -var build_tag=$(BUILD_TAG) -var source_ami_id=$(SOURCE_AMI_ID) eks-worker-al2.json
packer build -color=false -var build_tag=$(BUILD_TAG) -var source_ami_id=$(SOURCE_AMI_ID) eks-worker-bionic.json
18 changes: 5 additions & 13 deletions eks-worker-al2.json → eks-worker-bionic.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"variables": {
"aws_region": "us-west-2",
"build_tag": "",
"ami_name": "amazon-eks-node",
"ami_name": "bionic-eks-node",
"binary_bucket_name": "amazon-eks",
"binary_bucket_region": "us-west-2",
"binary_bucket_path": "1.10.3/2018-07-26/bin/linux/amd64",
Expand All @@ -21,26 +21,18 @@
"source_ami_filter": {
"filters": {
"architecture": "x86_64",
"name": "amzn2-ami-minimal-hvm-*",
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
"root-device-type": "ebs",
"state": "available",
"virtualization-type": "hvm"
},
"owners": [ "137112412989" ],
"owners": [ "099720109477" ],
"most_recent": true
},
"instance_type": "{{user `instance_type`}}",
"spot_price": "auto",
"spot_price_auto_product": "Linux/UNIX (Amazon VPC)",
"launch_block_device_mappings": [
{
"device_name": "/dev/xvda",
"volume_type": "gp2",
"volume_size": 20,
"delete_on_termination": true
}
],
"ssh_username": "ec2-user",
"ssh_username": "ubuntu",
"ssh_pty": true,
"encrypt_boot": "{{user `encrypted`}}",
"kms_key_id": "{{user `kms_key_id`}}",
Expand All @@ -51,7 +43,7 @@
"created": "{{timestamp}}"
},
"ami_name": "{{user `ami_name`}}-{{user `build_tag`}}",
"ami_description": "EKS Kubernetes Worker AMI with AmazonLinux2 image"
"ami_description": "EKS Kubernetes Worker AMI with Ubuntu 18.04 Bionic image"
}
],

Expand Down
2 changes: 1 addition & 1 deletion files/iptables-restore.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ After=docker.service

[Service]
Type=oneshot
ExecStart=/bin/bash -c "/sbin/iptables-restore < /etc/sysconfig/iptables"
ExecStart=/bin/bash -c "/sbin/iptables-restore < /etc/iptables.rules"

[Install]
WantedBy=multi-user.target
29 changes: 15 additions & 14 deletions install-worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,35 @@ TEMPLATE_DIR=${TEMPLATE_DIR:-/tmp/worker}
################################################################################

# Update the OS to begin with to catch up to the latest packages.
sudo yum update -y
sudo apt update
sudo apt-get update
sudo apt upgrade -y >/dev/null

# Install necessary packages
sudo yum install -y \
sudo apt-get install -y --no-install-recommends \
awscli \
aws-cfn-bootstrap \
conntrack \
curl \
htop \
nfs-utils \
nfs-common \
nmap \
ntp \
socat \
screen \
sysstat \
unzip \
wget
wget \
>/dev/null

sudo systemctl enable ntpd
sudo systemctl enable ntp

################################################################################
### iptables ###################################################################
################################################################################

# Enable forwarding via iptables
sudo iptables -P FORWARD ACCEPT
sudo bash -c "/sbin/iptables-save > /etc/sysconfig/iptables"
sudo bash -c "/sbin/iptables-save > /etc/iptables.rules"

sudo mv $TEMPLATE_DIR/iptables-restore.service /etc/systemd/system/iptables-restore.service

Expand All @@ -49,11 +51,9 @@ sudo systemctl enable iptables-restore
### Docker #####################################################################
################################################################################

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo amazon-linux-extras enable docker
sudo yum install -y docker-17.06*
sudo apt-get install -y --no-install-recommends docker.io=17.12.1-0ubuntu1
sudo usermod -aG docker $USER
sudo mkdir /etc/docker
sudo mkdir -p /etc/docker
sudo chown root:root /etc/docker
sudo chmod 700 /etc/docker
sudo mv $TEMPLATE_DIR/daemon.json /etc/docker/daemon.json
Expand Down Expand Up @@ -134,17 +134,18 @@ sudo mv $TEMPLATE_DIR/bootstrap.sh /etc/eks/bootstrap.sh
sudo chmod +x /etc/eks/bootstrap.sh

# Clean up yum caches to reduce the image size
sudo yum clean all
sudo apt-get autoremove -y
sudo rm -rf \
$TEMPLATE_DIR \
/var/cache/yum
/var/lib/apt/lists \
/var/cache/apt/archives

# Clean up files to reduce confusion during debug
sudo rm -rf \
/etc/machine-id \
/etc/ssh/ssh_host* \
/root/.ssh/authorized_keys \
/home/ec2-user/.ssh/authorized_keys \
/home/ubuntu/.ssh/authorized_keys \
/var/log/secure \
/var/log/wtmp \
/var/lib/cloud/sem \
Expand Down