Last active
April 1, 2024 21:44
-
-
Save c0dyhi11/5736ea79e8a246b5bbae5bd9894971be to your computer and use it in GitHub Desktop.
Ubuntu 20.04 Tinkerbell deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Become the root user because I didn't verifiy sudo for every command. | |
# Install Tinkerbell | |
sudo apt-get update -y | |
sudo apt-get install -y apt-transport-https \ | |
ca-certificates \ | |
curl \ | |
gnupg-agent \ | |
ifupdown \ | |
jq \ | |
software-properties-common \ | |
git \ | |
build-essential \ | |
net-tools \ | |
ipmitool \ | |
wakeonlan \ | |
qemu-utils | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt-get update -y | |
sudo apt-get install -y docker-ce docker-ce-cli containerd.io | |
sudo curl -L \ | |
"https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" \ | |
-o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
sudo mkdir -p /srv/ | |
cd /srv | |
git clone https://github.com/tinkerbell/sandbox.git tinkerbell | |
cd tinkerbell | |
INTERFACE=$(ip r | grep default |awk '{print $5}') | |
TINK_IP=$(ifconfig $INTERFACE | grep broadcast | awk '{print $2}') | |
TINK_CIDR=$(ip a | grep $TINK_IP | awk '{print $2}' | awk -F'/' '{print $2}') | |
./generate-env.sh $INTERFACE > .env | |
sed -i "s/export TINKERBELL_CIDR=29/export TINKERBELL_CIDR=$TINK_CIDR/g" .env | |
sed -i "s/export TINKERBELL_HOST_IP=192.168.1.1/export TINKERBELL_HOST_IP=$TINK_IP/g" .env | |
source .env | |
sudo bash setup.sh | |
cd deploy | |
docker-compose up -d | |
cd .. | |
echo "source /srv/tinkerbell/.env ; alias tink='docker exec -i deploy_tink-cli_1 tink'" > ~/.bash_aliases | |
source ~/.bash_aliases | |
# Load images | |
PUBLIC_REGISTRY="quay.io/tinkerbell-actions" | |
PRIVATE_REGISTRY=$TINK_IP | |
IMAGES=( "image2disk:v1.0.0" "kexec:v1.0.0" "rootio:v1.0.0" "archive2disk:v1.0.0" "cexec:v1.0.0" "writefile:v1.0.0" "slurp:v1.0.0" "oci2disk:v1.0.0" "syslinux:v1.0.0" ) | |
for i in "${IMAGES[@]}"; do | |
docker pull $PUBLIC_REGISTRY/$i | |
docker tag $PUBLIC_REGISTRY/$i $PRIVATE_REGISTRY/$i | |
docker push $PRIVATE_REGISTRY/$i | |
done | |
docker pull hello-world | |
docker tag hello-world $PRIVATE_REGISTRY/hello-world | |
docker push $PRIVATE_REGISTRY/hello-world | |
# Load Operating System Images | |
mkdir -p /srv/tinkerbell/deploy/state/webroot/images/ | |
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img | |
qemu-img convert focal-server-cloudimg-amd64.img -O raw /srv/tinkerbell/deploy/state/webroot/images/focal-server-cloudimg-amd64.raw | |
gzip /srv/tinkerbell/deploy/state/webroot/images/focal-server-cloudimg-amd64.raw | |
rm -f focal-server-cloudimg-amd64.img | |
# Replace OSIE with Hook | |
cd | |
git clone https://github.com/linuxkit/linuxkit | |
cd linuxkit | |
git checkout | |
make | |
make install | |
cd .. | |
git clone https://github.com/tinkerbell/hook.git | |
cd hook | |
mkdir -p out ccece6a4889e15850dfbaf6d5170939c83edb103 | |
linuxkit build -docker -pull -format kernel+initrd -name hook-x86_64 -dir out hook.yaml | |
mv out/hook-x86_64-kernel out/vmlinuz-x86_64 | |
mv out/hook-x86_64-initrd.img out/initramfs-x86_64 | |
mv /srv/tinkerbell/deploy/state/webroot/misc/osie/current/ /srv/tinkerbell/deploy/state/webroot/misc/osie/osie/ | |
mv out/ /srv/tinkerbell/deploy/state/webroot/misc/osie/current/ | |
# Do a little cleanup | |
cd | |
rm -rf hook linuxkit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tink hardware push < server01.json | |
TEMPLATE_ID=$(tink template create < templates/ubuntu_20.04.yaml | awk '{print $3}') | |
tink workflow create -t $TEMPLATE_ID -r ' | |
{ | |
"global":{ | |
"http_mirror": "http://192.168.161.2:8080" | |
}, | |
"hardware": { | |
"mac_address": "3c:ec:ef:76:5e:2e", | |
"nic_name": "eno1", | |
"disk": { | |
"dev": "/dev/nvme0n1", | |
"partition": "/dev/nvme0n1p1" | |
} | |
}, | |
"identity": { | |
"hostname": "myinstance", | |
"username": "ubuntu", | |
"ssh_keys": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQD2uzwCmJcAmu2ktAonU/drli8cM4Sk5Nl0pq+gtK7EM75yA0LdufgP26CSYsLUf/Piaw+7Lcp++gim48zNeogAc9BbZXigY97pzJQdo8GIhIyhv0NTYAyIMlLWn85Hh5poxPm2/uZ3CoCcKK0msyQfCsCn61Hn1PrzT5TXSbZmGPnED+Pe0PdSRrMFdbOyGjDyZod69hqZVUhO5WziIbBEKArEQdGf73Utz7jTOFcIFUVV+zCmOPsqrX9vFpOdLdntIVg0zYpnWsxGZ+MXibMlP9s9rMxYYJd8a4lvG0QpJrHXb0LUBZtzD/Vn5VxFbVX3XJMejrXdLB3CSNCj0xPlvkGNaql14loQnGBLfM4OHTtMRCXHq5ON4p18pHL+6hMSuj5PUFJwOS89+U+J6J3p4KiRtqM951UgMIWSEVpUs74jTrpLbbnXiXWzC9ThM84YrEusFwn1qvlr/u6/itaam/8qxB8rIshlSRfS3t5EBJvdWX0lJTeLojyoKb8PqWiBXaVRk/bQlApbIr3pcY2FPt6bek3BlNoRuUtu5tsNbSENtjIZ8J39pmypDkZtJpmUIRO1kGTzqF98R9P8AEd9Hd6ePnQmNT10RJfcGaJoOzx3XHHhOLZeHYaHs9x54X8GSG2Z+tG61wYg3bPY8yVsJdgD856608N4XIA9dyQluQ== [email protected]", | |
"user_data": "IyEvYmluL2Jhc2gKZWNobyAiSGVsbG8gd29ybGQgZnJvbSB0aW5rZXJiZWxsISIgPiAvcm9vdC9oZWxsb193b3JsZC50eHQK" | |
} | |
}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Download Ubuntu image | |
SANDBOX_WEB_ROOT="/srv/tinkerbell/deploy/state/webroot" | |
apt-get update -y | |
apt-get install -y qemu-utils | |
mkdir -p $SANDBOX_REPO_ROOT/images/ | |
wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img | |
qemu-img convert focal-server-cloudimg-amd64.img -O raw $SANDBOX_WEB_ROOT/images/focal-server-cloudimg-amd64.raw | |
gzip $SANDBOX_WEB_ROOT/images/focal-server-cloudimg-amd64.raw | |
rm -f focal-server-cloudimg-amd64.img | |
# Place the netplan file | |
mkdir -p $SANDBOX_WEB_ROOT/configs | |
cat <<-EOF > $SANDBOX_WEB_ROOT/configs/netplan.yaml | |
network: | |
ethernets: | |
__INTERFACE__: | |
dhcp4: true | |
version: 2 | |
EOF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": "6da7c158-1095-4974-8f8f-b90b166da77e", | |
"network": { | |
"interfaces": [ | |
{ | |
"dhcp": { | |
"arch": "x86_64", | |
"hostname": "server01", | |
"ip": { | |
"address": "192.168.161.5", | |
"gateway": "192.168.161.254", | |
"netmask": "255.255.255.0" | |
}, | |
"mac": "3c:ec:ef:76:5e:2e", | |
"uefi": false | |
}, | |
"netboot": { | |
"allow_pxe": true, | |
"allow_workflow": true | |
} | |
} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "0.1" | |
name: Ubuntu_Focal_Image | |
global_timeout: 1800 | |
tasks: | |
- name: "os-installation" | |
worker: "{{.hardware.mac_address}}" | |
volumes: | |
- /dev:/dev | |
- /dev/console:/dev/console | |
- /lib/firmware:/lib/firmware:ro | |
actions: | |
- name: "stream-os-image" | |
image: image2disk:v1.0.0 | |
timeout: 600 | |
environment: | |
DEST_DISK: "{{.hardware.disk.dev}}" | |
IMG_URL: "{{.global.http_mirror}}/images/focal-server-cloudimg-amd64.raw.gz" | |
COMPRESSED: true | |
- name: grow-root-fs | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
growpart {{.hardware.disk.dev}} 1; | |
resize2fs {{.hardware.disk.partition}} | |
- name: set-hostname | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
echo {{.identity.hostname}} > /etc/hostname | |
- name: enable-passwordless-sudo | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
sed -i "s/%sudo\tALL=(ALL:ALL) ALL/%sudo\tALL=(ALL:ALL) NOPASSWD:ALL/g" /etc/sudoers | |
- name: "generate-ssh-keys" | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
ssh-keygen -A | |
- name: "set-root-password" | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
echo 'root:L3tM3!nM@n' | chpasswd | |
- name: "configure-user" | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
useradd -s /bin/bash -G sudo {{.identity.username}}; | |
mkdir -p /home/{{.identity.username}}/.ssh; | |
echo {{.identity.ssh_keys}} >> /home/{{.identity.username}}/.ssh/authorized_keys; | |
chown -R {{.identity.username}}:{{.identity.username}} /home/{{.identity.username}}; | |
chmod 0700 /home/{{.identity.username}}/.ssh; | |
chmod 0600 /home/{{.identity.username}}/.ssh/authorized_keys | |
- name: "add-network-config" | |
image: cexec:v1.0.0 | |
timeout: 90 | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 | |
CHROOT: y | |
DEFAULT_INTERPRETER: "/bin/sh -c" | |
CMD_LINE: | |
curl -Lo /etc/netplan/00-tinkerbell-config.yaml {{.global.http_mirror}}/configs/netplan.yaml; | |
sed -i "s/__INTERFACE__/{{.hardware.nic_name}}/g" /etc/netplan/00-tinkerbell-config.yaml | |
- name: "kexec-os" | |
image: kexec:v1.0.0 | |
timeout: 90 | |
pid: host | |
environment: | |
BLOCK_DEVICE: "{{.hardware.disk.partition}}" | |
FS_TYPE: ext4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment