├── README.md ├── aws-ami.json ├── build-image-11-0 └── create-aws-ami /README.md: -------------------------------------------------------------------------------- 1 | # Experimental and Work In Progress 2 | ### Kubernetes and FreeBSD 11.0 3 | 4 | Notes, Documentation, and Convenience scripts for running Kubernetes on FreeBSD 5 | 6 | ## `build-image-11-0` 7 | 8 | This is a convenience script that holds all the logic and dependency lists for installing the following components on a FreeBSD 11.0 image. 9 | 10 | - `docker` 11 | - `emacs25` 12 | - `bash` 13 | - `sudo` 14 | - `cloud-init` 15 | -------------------------------------------------------------------------------- /aws-ami.json: -------------------------------------------------------------------------------- 1 | { 2 | "DryRun": false, 3 | "ImageId": "ami-028c2862", 4 | "MinCount": 0, 5 | "MaxCount": 0, 6 | "KeyName": "", 7 | "SecurityGroups": [ 8 | "kubernetes-freebsd-ami-create" 9 | ], 10 | "SecurityGroupIds": [ 11 | "${SGID}" 12 | ], 13 | "UserData": "", 14 | "InstanceType": "", 15 | "Placement": { 16 | "AvailabilityZone": "", 17 | "GroupName": "", 18 | "Tenancy": "" 19 | }, 20 | "KernelId": "", 21 | "RamdiskId": "", 22 | "BlockDeviceMappings": [ 23 | { 24 | "VirtualName": "", 25 | "DeviceName": "", 26 | "Ebs": { 27 | "SnapshotId": "", 28 | "VolumeSize": 0, 29 | "DeleteOnTermination": true, 30 | "VolumeType": "", 31 | "Iops": 0, 32 | "Encrypted": true 33 | }, 34 | "NoDevice": "" 35 | } 36 | ], 37 | "Monitoring": { 38 | "Enabled": true 39 | }, 40 | "SubnetId": "", 41 | "DisableApiTermination": true, 42 | "InstanceInitiatedShutdownBehavior": "", 43 | "PrivateIpAddress": "", 44 | "ClientToken": "", 45 | "AdditionalInfo": "", 46 | "NetworkInterfaces": [ 47 | { 48 | "NetworkInterfaceId": "", 49 | "DeviceIndex": 0, 50 | "SubnetId": "", 51 | "Description": "", 52 | "PrivateIpAddress": "", 53 | "Groups": [ 54 | "" 55 | ], 56 | "DeleteOnTermination": true, 57 | "PrivateIpAddresses": [ 58 | { 59 | "PrivateIpAddress": "", 60 | "Primary": true 61 | } 62 | ], 63 | "SecondaryPrivateIpAddressCount": 0, 64 | "AssociatePublicIpAddress": true 65 | } 66 | ], 67 | "IamInstanceProfile": { 68 | "Arn": "", 69 | "Name": "" 70 | }, 71 | "EbsOptimized": true 72 | } 73 | -------------------------------------------------------------------------------- /build-image-11-0: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ----------------------------------------------------------------------------- 3 | # Copyright [2017] [Kris Nova] kris@nivenly.com 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | # ----------------------------------------------------------------------------- 18 | # 19 | # build-image is an idempotent script that can be used to turn a vanilla 20 | # FreeBSD 11 image into an image that is tweaked to run Docker and Kubernetes 21 | # out of the box. By design this script can be run at any point on a FreeBSD 11 22 | # system and as long as not conflicts are detected, will provision the machine. 23 | # 24 | # 25 | # Tested on FreeBSD 11.0 in Amazon Web Services US-WEST-2 26 | # FreeBSD 11.0-STABLE-amd64-2016-10-22 - ami-028c2862 27 | # FreeBSD 11.0-STABLE-amd64 28 | # 29 | # ----------------------------------------------------------------------------- 30 | 31 | 32 | INSTALL_ADMIN_PKGS=1 33 | 34 | # Install administrative packages 35 | if [ "$INSTALL_ADMIN_PKGS" -eq "1" ]; then 36 | echo "Installing administrative packages.." 37 | pkg install -y bash 38 | mount -t fdescfs fdescfs /dev/fd 39 | pkg install -y emacs25 40 | pkg install -y git 41 | pkg install -y sudo 42 | sudo echo "fdescfs /dev/fd fdescfs rw,late 0 0" >> /etc/fstab 43 | fi 44 | 45 | # Install Docker 46 | if hash docker 2>/dev/null; then 47 | echo "Installing Docker.." 48 | kldload zfs 49 | dd if=/dev/zero of=/usr/local/dockerfs bs=1024K count=4000 50 | zpool create -f zroot /usr/local/dockerfs 51 | zfs create -o mountpoint=/var/lib/docker zroot/docker 52 | pkg install -y docker-freebsd ca_root_nss 53 | sysrc -f /etc/rc.conf docker_enable="YES" 54 | zfs mount -a 55 | echo "zfs mount -a" >> /usr/local/etc/rc.d/docker 56 | service docker start 57 | service docker status 58 | fi 59 | 60 | # Install cloud-init thanks to https://github.com/number5/cloud-init and Ubuntu <3 <# 61 | if hash cloud-init 2>/dev/null; then 62 | echo "Installing cloud-init.." 63 | cd ~ 64 | git clone https://github.com/number5/cloud-init.git 65 | cd cloud-init 66 | 67 | # Pending PR: https://github.com/number5/cloud-init/pull/14 we are using my fork 68 | # but the credit goes to number5 and their original script. 69 | # fetch https://raw.githubusercontent.com/number5/cloud-init/master/tools/build-on-freebsd 70 | fetch https://raw.githubusercontent.com/kris-nova/cloud-init/patch-1/tools/build-on-freebsd 71 | sh build-on-free-bsd 72 | fi 73 | -------------------------------------------------------------------------------- /create-aws-ami: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IP=$(curl -s ifconfig.me) 4 | REGION="us-west-2" 5 | 6 | # Create a security group 7 | SGID=$(aws ec2 create-security-group \ 8 | --group-name "kubernetes-freebsd-ami-create" \ 9 | --description "Security group for creating a FreeBSD AMI" \ 10 | --region $REGION) 11 | 12 | 13 | # SSH access 14 | aws ec2 authorize-security-group-ingress \ 15 | --group-name "kubernetes-freebsd-ami-create" \ 16 | --protocol tcp \ 17 | --port 22 \ 18 | --cidr $IP/32 \ 19 | --region $REGION 20 | 21 | 22 | sed -i -e 's/<>/${SGID}/g' aws-ami.json 23 | O=$(aws ec2 run-instances --cli-input-json file://aws-ami.json) 24 | echo $O 25 | 26 | # Kris TODO parse the CNAME out of the AWS API and run the following command 27 | # ssh -i ~/.ssh/id_rsa ec2-user@${CNAME} cd ~ && fetch https://github.com/kris-nova/kubernetes-freebsd/blob/master/build-image && sh build-image 28 | 29 | # Kris TODO create an AMI from the instance 30 | 31 | # Kris TODO delete the instance 32 | 33 | # Kris TODO delete the security group 34 | 35 | # Kris TODO Profit --------------------------------------------------------------------------------