LoginSignup
0
0

KVMでk8sクラスタを自動で作成する

Posted at

master

k8sdep.sh

#!/bin/bash
cd `dirname $0`

rm /home/yamato/kubetoken
virt-clone --original ubuntu2 --name ubuntu-k8s-master-$1 --file /var/lib/libvirt/images/ubuntu-k8s-master-$1.qcow2



virt-edit -d ubuntu-k8s-master-$1 /etc/netplan/00-installer-config.yaml -e "s/172.24.20.30/172.24.20.$1/"
virt-edit -d ubuntu-k8s-master-$1 /etc/hostname -e "s/ubuntu-k8s-master/ubuntu-k8s-master-$1/"

virsh start ubuntu-k8s-master-$1

worker

k8swordep.sh

#!/bin/bash
cd `dirname $0`

virt-clone --original ubuntu3 --name ubuntu-k8s-worker-$1 --file /var/lib/libvirt/images/ubuntu-k8s-worker-$1.qcow2



virt-edit -d ubuntu-k8s-worker-$1 /etc/netplan/00-installer-config.yaml -e "s/172.24.20.31/172.24.20.$1/"
virt-edit -d ubuntu-k8s-worker-$1 /etc/hostname -e "s/ubuntu-k8s-worker/ubuntu-k8s-worker-$1/"


virt-edit -d ubuntu-k8s-worker-$1 /etc/rc.sh -e "s/172.24.20.30/172.24.20.$3/"
TT="--token kgu8yd.3b83hmhjeesqpqz3 --discovery-token-ca-cert-hash sha256:c3262b24e5b222fcc09affb10efd66e59ba821b443f82e4ec28a45e9e86883bc"
virt-edit -d ubuntu-k8s-worker-$1 /etc/rc.sh -e "s/$TT/$4/"

cp -p /var/lib/libvirt/images/k8s.qcow2 /var/lib/libvirt/images/k8s-$1.qcow2


mozi="<disk type='file' device='disk'><driver name='qemu' type='qcow2' cache='none'/><source file='/var/lib/libvirt/images/k8s-$1.qcow2'/><target dev='vdb' bus='virtio'/><address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/></disk><disk type='file' device='cdrom'>"
mozi1="<disk type='file' device='cdrom'>"


sed -e "s#$mozi1#$mozi#g" -i /etc/libvirt/qemu/ubuntu-k8s-worker-$1.xml





virsh define /etc/libvirt/qemu/ubuntu-k8s-worker-$1.xml
virsh start ubuntu-k8s-worker-$1

k8swordep.py

import os,sys,time

args = sys.argv

ip1 = args[1]
ip = int(ip1)

num1 = args[2]
num = int(num1)

masip = args[3]
token = args[4]

while num > 0:

    com = "/home/yamato/image/k8swordep.sh " +"\""+ str(ip) +"\"" + " "+"\""+ str(num) +"\"" + " "+"\""+ str(masip) +"\"" + " "+"\""+ str(token) +"\""
    print(com)
    os.system(com)
    ip = ip + 1
    num = num - 1
    time.sleep(5)

print("VM作成完了")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0