maas-baremetal-k8s-tutorial/maas-setup.sh

132 lines
4.9 KiB
Bash
Raw Normal View History

# lxd / maas issue. either upgrade lxd or maas to 3.1
sudo snap switch --channel=4.19/stable lxd
sudo snap refresh lxd
2021-11-16 16:41:11 +00:00
sudo snap install jq
2021-11-16 12:47:15 +00:00
sudo snap install --channel=3.1/beta maas
2021-11-16 16:40:14 +00:00
sudo snap install --channel=3.1/beta maas-test-db
2021-11-16 21:06:29 +00:00
# clone the git repository
git clone https://github.com/antongisli/maas-baremetal-k8s-tutorial.git
# get local interface name (this assumes a single default route is present)
2021-10-27 10:57:40 +00:00
export INTERFACE=$(ip route | grep default | cut -d ' ' -f 5)
export IP_ADDRESS=$(ip -4 addr show dev $INTERFACE | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
2021-11-16 16:02:39 +00:00
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sysctl -p
sudo iptables -t nat -A POSTROUTING -o $INTERFACE -j SNAT --to $IP_ADDRESS
2021-10-27 10:57:40 +00:00
#TODO inbound port forwarding/load balancing
# Persist NAT configuration
echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
2021-11-16 16:02:39 +00:00
sudo apt-get install iptables-persistent -y
2021-10-27 10:57:40 +00:00
# LXD init
2021-11-16 21:06:29 +00:00
sudo cat /maas-baremetal-k8s-tutorial/lxd.cfg | lxd init --preseed
2021-10-27 10:57:40 +00:00
# Wait for LXD to be ready
lxd waitready
# Initialise MAAS
2021-11-16 16:02:39 +00:00
sudo maas init region+rack --database-uri maas-test-db:/// --maas-url http://${IP_ADDRESS}:5240/MAAS
2021-10-27 10:57:40 +00:00
sleep 15
# Create MAAS admin and grab API key
maas createadmin --username admin --password admin --email admin
2021-11-16 16:02:39 +00:00
export APIKEY=$(sudo maas apikey --username admin)
2021-10-27 10:57:40 +00:00
# MAAS admin login
maas login admin 'http://localhost:5240/MAAS/' $APIKEY
# Configure MAAS networking (set gateways, vlans, DHCP on etc)
export SUBNET=10.10.10.0/24
export FABRIC_ID=$(maas admin subnet read "$SUBNET" | jq -r ".vlan.fabric_id")
export VLAN_TAG=$(maas admin subnet read "$SUBNET" | jq -r ".vlan.vid")
export PRIMARY_RACK=$(maas admin rack-controllers read | jq -r ".[] | .system_id")
maas admin subnet update $SUBNET gateway_ip=10.10.10.1
maas admin ipranges create type=dynamic start_ip=10.10.10.200 end_ip=10.10.10.254
maas admin vlan update $FABRIC_ID $VLAN_TAG dhcp_on=True primary_rack=$PRIMARY_RACK
maas admin maas set-config name=upstream_dns value=8.8.8.8
# Add LXD as a VM host for MAAS and capture the VM_HOST_ID
VM_HOST_ID=maas admin vm-hosts create password=password type=lxd power_address=https://${IP_ADDRESS}:8443 \
project=maas | jq '.id'
2021-10-27 10:57:40 +00:00
2021-11-03 17:08:33 +00:00
### creating VMs for Juju controller and our "bare metal"
2021-11-02 20:29:15 +00:00
# add a VM for the juju controller with minimal memory
2021-11-16 16:40:14 +00:00
maas admin vm-host compose $VM_HOST_ID cores=8 memory=2048 architecture="amd64/generic" \
storage="main:16(pool1)" hostname="juju-controller"
2021-11-03 17:08:33 +00:00
# get the system-id and tag the machine with "juju-controller"
2021-11-16 16:40:14 +00:00
JUJU_SYSID=$(maas admin machines read | jq '.[]
| select(."hostname"=="juju-controller")
| .["system_id"]' | tr -d '"')
2021-11-03 17:08:33 +00:00
maas admin tag update-nodes "juju-controller" add=$JUJU_SYSID
2021-10-27 10:57:40 +00:00
2021-11-03 17:08:33 +00:00
## Create 3 "bare metal" machines and tag them with "metal"
for ID in 1 2 3
do
2021-11-16 16:40:14 +00:00
maas admin vm-host compose $VM_HOST_ID cores=8 memory=8192 architecture="amd64/generic" \
storage="main:25(pool1),ceph:150(pool1)" hostname="metal-${ID}"
SYSID=$(maas admin machines read | jq -r --arg MACHINE "metal-${ID}" '.[]
| select(."hostname"==$MACHINE)
| .["system_id"]' | tr -d '"')
maas admin tag update-nodes "metal" add=$SYSID
done
2021-11-03 13:13:00 +00:00
### Juju setup (note, this section requires manual intervention)
cd ~
2021-10-27 10:57:40 +00:00
sudo snap install juju --classic
sed -i 's/IP_ADDRESS/${IP_ADDRESS}/' maas-cloud.yaml
2021-10-27 10:57:40 +00:00
juju add-cloud --local maas-cloud maas-cloud.yaml
juju add-credential maas-cloud
juju clouds --local
juju credentials
2021-11-02 20:29:15 +00:00
# Bootstrap the maas-cloud - get a coffee
juju bootstrap maas-cloud --bootstrap-constraints "tags=juju-controller mem=2G"
# fire up the juju gui to view the fun
juju gui
# get coffee
2021-11-03 13:13:00 +00:00
### Ceph
2021-11-02 20:29:15 +00:00
juju deploy -n 3 ceph-mon --to lxd:0,lxd:1,lxd:2
juju deploy --config ceph-osd.yaml cs:ceph-osd -n 3 --to 0,1,2
juju add-relation ceph-mon ceph-osd
2021-11-03 13:13:00 +00:00
# watch the fun (with a another coffee).
2021-11-02 20:29:15 +00:00
watch -c juju status --color
2021-11-03 13:13:00 +00:00
# Wait for Ceph to settle before proceeding
2021-11-02 20:29:15 +00:00
2021-11-03 13:13:00 +00:00
### Kubernetes
# Deploy kubernetes-core with juju and re-use existing machines.
juju deploy kubernetes-core --map-machines=existing,0=0,1=1
2021-11-03 13:13:00 +00:00
# add the new kubernetes as a cloud to juju
mkdir ~/.kube
2021-11-03 13:13:00 +00:00
juju scp kubernetes-master/1:/home/ubuntu/config ~/.kube/config
# add storage relations
juju add-relation ceph-mon:admin kubernetes-master
juju add-relation ceph-mon:client kubernetes-master
2021-11-03 13:13:00 +00:00
# add k8s to juju (choose option 1, client only)
juju add-k8s my-k8s
2021-11-03 13:13:00 +00:00
juju bootstrap my-k8s
2021-11-03 13:13:00 +00:00
### Deploying applications
# juju add-model some-model my-k8s
# juju deploy someapp(s)
### Cleanup? not sure this always works.
#juju destroy-controller -y --destroy-all-models --destroy-storage maas-cloud-default
### Notes / LMA stack deployment
## add an LMA model to the cluster
juju add-model lma my-k8s
juju deploy lma-light --channel=edge --trust
2021-11-03 13:13:00 +00:00
## random notes
# get some storage going
# https://jaas.ai/ceph-base
2021-11-16 12:47:15 +00:00
# https://jaas.ai/canonical-kubernetes/bundle/471