Merge pull request #2032 from ijc/kubernetes

Small improvements to projects/kubernetes
This commit is contained in:
Riyaz Faizullabhoy 2017-06-13 10:41:25 -07:00 committed by GitHub
commit c1950419ef
17 changed files with 109 additions and 47 deletions

View File

@ -13,7 +13,7 @@ make build-vm-images
Boot Kubernetes master OS image using `hyperkit` on macOS: Boot Kubernetes master OS image using `hyperkit` on macOS:
``` ```
./boot-master.sh ./boot.sh
``` ```
Get IP address of the master: Get IP address of the master:
@ -36,12 +36,12 @@ and try `kubectl get nodes` from within the master.
To boot a node use: To boot a node use:
``` ```
./boot-node.sh <n> [<join_args> ...] ./boot.sh <n> [<join_args> ...]
``` ```
More specifically, to start 3 nodes use 3 separate shells and run this: More specifically, to start 3 nodes use 3 separate shells and run this:
``` ```
shell1> ./boot-node.sh 1 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443 shell1> ./boot.sh 1 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell2> ./boot-node.sh 2 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443 shell2> ./boot.sh 2 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell3> ./boot-node.sh 3 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443 shell3> ./boot.sh 3 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
``` ```

View File

@ -1,5 +0,0 @@
#!/bin/bash -eu
disk="kube-master-disk.img"
set -x
rm -f "${disk}"
../../bin/linuxkit run -cpus 2 -mem 4096 -disk "${disk}",size=4G kube-master

View File

@ -1,8 +0,0 @@
#!/bin/bash -eu
[ "${#@}" -gt 1 ] || (echo "Usage: ${0} <node> <join_args>" ; exit 1)
name="node-${1}"
shift
disk="kube-${name}-disk.img"
set -x
rm -f "${disk}"
../../bin/linuxkit run -cpus 2 -mem 4096 -disk "${disk}",size=4G -data "${*}" kube-node

22
projects/kubernetes/boot.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash -eu
if [ $# -eq 0 ] ; then
img="kube-master"
data=""
state="kube-master-state"
elif [ $# -gt 1 ] ; then
img="kube-node"
name="node-${1}"
shift
data="${*}"
state="kube-${name}-state"
else
echo "Usage:"
echo " - Boot master:"
echo " ${0}"
echo " - Boot node:"
echo " ${0} <node> <join_args>"
exit 1
fi
set -x
rm -rf "${state}"
../../bin/linuxkit run -cpus 2 -mem 4096 -state "${state}" -disk size=4G -data "${data}" "${img}"

View File

@ -2,7 +2,7 @@ kernel:
image: "linuxkit/kernel:4.9.x" image: "linuxkit/kernel:4.9.x"
cmdline: "console=ttyS0 console=tty0 page_poison=1" cmdline: "console=ttyS0 console=tty0 page_poison=1"
init: init:
- linuxkit/init:1b8a7e394d2ec2f1fdb4d67645829d1b5bdca037 - linuxkit/init:2599bcd5013ce5962aa155ee8929c26160de13bd
- linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f
- linuxkit/containerd:b50181bc6e0084e5fcd6b6ad3cf433c4f66cae5a - linuxkit/containerd:b50181bc6e0084e5fcd6b6ad3cf433c4f66cae5a
- linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d
@ -25,6 +25,10 @@ onboot:
- /dev:/dev - /dev:/dev
- /var:/var:rshared,rbind - /var:/var:rshared,rbind
services: services:
- name: getty
image: "linuxkit/getty:148946d72d1c96df3ea91cb8ee4f9583cd3cc5c2"
env:
- INSECURE=true
- name: rngd - name: rngd
image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31" image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31"
- name: dhcpcd - name: dhcpcd

View File

@ -2,7 +2,7 @@ kernel:
image: "linuxkit/kernel:4.9.x" image: "linuxkit/kernel:4.9.x"
cmdline: "console=ttyS0 console=tty0 page_poison=1" cmdline: "console=ttyS0 console=tty0 page_poison=1"
init: init:
- linuxkit/init:1b8a7e394d2ec2f1fdb4d67645829d1b5bdca037 - linuxkit/init:2599bcd5013ce5962aa155ee8929c26160de13bd
- linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f
- linuxkit/containerd:b50181bc6e0084e5fcd6b6ad3cf433c4f66cae5a - linuxkit/containerd:b50181bc6e0084e5fcd6b6ad3cf433c4f66cae5a
- linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d
@ -25,6 +25,10 @@ onboot:
- /dev:/dev - /dev:/dev
- /var:/var:rshared,rbind - /var:/var:rshared,rbind
services: services:
- name: getty
image: "linuxkit/getty:148946d72d1c96df3ea91cb8ee4f9583cd3cc5c2"
env:
- INSECURE=true
- name: rngd - name: rngd
image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31" image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31"
- name: dhcpcd - name: dhcpcd

View File

@ -20,11 +20,12 @@ const QemuImg = "linuxkit/qemu:c9691f5c50dd191e62b77eaa2f3dfd05ed2ed77c"
// QemuConfig contains the config for Qemu // QemuConfig contains the config for Qemu
type QemuConfig struct { type QemuConfig struct {
Path string Path string
ISO bool ISOBoot bool
UEFI bool UEFI bool
Kernel bool Kernel bool
GUI bool GUI bool
Disks Disks Disks Disks
MetadataPath string
FWPath string FWPath string
Arch string Arch string
CPUs string CPUs string
@ -55,9 +56,13 @@ func runQemu(args []string) {
isoBoot := flags.Bool("iso", false, "Boot image is an ISO") isoBoot := flags.Bool("iso", false, "Boot image is an ISO")
kernelBoot := flags.Bool("kernel", false, "Boot image is kernel+initrd+cmdline 'path'-kernel/-initrd/-cmdline") kernelBoot := flags.Bool("kernel", false, "Boot image is kernel+initrd+cmdline 'path'-kernel/-initrd/-cmdline")
// State flags
state := flags.String("state", "", "Path to directory to keep VM state in")
// Paths and settings for disks // Paths and settings for disks
var disks Disks var disks Disks
flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]") flags.Var(&disks, "disk", "Disk config, may be repeated. [file=]path[,size=1G][,format=qcow2]")
data := flags.String("data", "", "Metadata to pass to VM (either a path to a file or a string)")
// Paths and settings for UEFI firware // Paths and settings for UEFI firware
fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot") fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot")
@ -110,6 +115,35 @@ func runQemu(args []string) {
} }
} }
if *state == "" {
*state = prefix + "-state"
}
var mkstate func()
mkstate = func() {
if err := os.MkdirAll(*state, 0755); err != nil {
log.Fatalf("Could not create state directory: %v", err)
}
mkstate = func() {}
}
isoPath := ""
if *data != "" {
var d []byte
if _, err := os.Stat(*data); os.IsNotExist(err) {
d = []byte(*data)
} else {
d, err = ioutil.ReadFile(*data)
if err != nil {
log.Fatalf("Cannot read user data: %v", err)
}
}
mkstate()
isoPath = filepath.Join(*state, "data.iso")
if err := WriteMetadataISO(isoPath, d); err != nil {
log.Fatalf("Cannot write user data ISO: %v", err)
}
}
for i, d := range disks { for i, d := range disks {
id := "" id := ""
if i != 0 { if i != 0 {
@ -119,7 +153,8 @@ func runQemu(args []string) {
d.Format = "qcow2" d.Format = "qcow2"
} }
if d.Size != 0 && d.Path == "" { if d.Size != 0 && d.Path == "" {
d.Path = prefix + "-disk" + id + ".img" mkstate()
d.Path = filepath.Join(*state, "disk"+id+".img")
} }
if d.Path == "" { if d.Path == "" {
log.Fatalf("disk specified with no size or name") log.Fatalf("disk specified with no size or name")
@ -134,13 +169,18 @@ func runQemu(args []string) {
disks = append(d, disks...) disks = append(d, disks...)
} }
if *isoBoot && isoPath != "" {
log.Fatalf("metadata and ISO boot currently cannot coexist")
}
config := QemuConfig{ config := QemuConfig{
Path: path, Path: path,
ISO: *isoBoot, ISOBoot: *isoBoot,
UEFI: *uefiBoot, UEFI: *uefiBoot,
Kernel: *kernelBoot, Kernel: *kernelBoot,
GUI: *enableGUI, GUI: *enableGUI,
Disks: disks, Disks: disks,
MetadataPath: isoPath,
FWPath: *fw, FWPath: *fw,
Arch: *arch, Arch: *arch,
CPUs: *cpus, CPUs: *cpus,
@ -214,20 +254,22 @@ func runQemuContainer(config QemuConfig) error {
} }
var binds []string var binds []string
if filepath.IsAbs(config.Path) { addBind := func(p string) {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(config.Path))) if filepath.IsAbs(p) {
} else { binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(p)))
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", cwd))
}
// also try to bind mount disk paths so the command works
for _, d := range config.Disks {
if filepath.IsAbs(d.Path) {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(d.Path)))
} else { } else {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", cwd)) binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", cwd))
} }
} }
addBind(config.Path)
if config.MetadataPath != "" {
addBind(config.MetadataPath)
}
// also try to bind mount disk paths so the command works
for _, d := range config.Disks {
addBind(d.Path)
}
var args []string var args []string
config, args = buildQemuCmdline(config) config, args = buildQemuCmdline(config)
@ -314,7 +356,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
for i, d := range config.Disks { for i, d := range config.Disks {
index := i index := i
// hdc is CDROM in qemu // hdc is CDROM in qemu
if i >= 2 && config.ISO { if i >= 2 && config.ISOBoot {
index++ index++
} }
if d.Format != "" { if d.Format != "" {
@ -324,9 +366,11 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
} }
} }
if config.ISO { if config.ISOBoot {
qemuArgs = append(qemuArgs, "-cdrom", config.Path) qemuArgs = append(qemuArgs, "-cdrom", config.Path)
qemuArgs = append(qemuArgs, "-boot", "d") qemuArgs = append(qemuArgs, "-boot", "d")
} else if config.MetadataPath != "" {
qemuArgs = append(qemuArgs, "-cdrom", config.MetadataPath)
} }
if config.UEFI { if config.UEFI {

View File

@ -12,7 +12,7 @@ NAME=check
clean_up() { clean_up() {
# remove any images # remove any images
find . -iname "${NAME}*" -exec rm {} \; find . -depth -iname "${NAME}*" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-kernel-config*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -13,7 +13,7 @@ IMAGE_NAME="kmod-test"
clean_up() { clean_up() {
docker rmi ${IMAGE_NAME} || true docker rmi ${IMAGE_NAME} || true
find . -iname "kmod*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "kmod*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-binfmt*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-binfmt*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-ca-certificates*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-ca-certificates*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-dhcpcd*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-dhcpcd*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,9 +10,10 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "run*" -not -iname "*.yml" -exec rm -rf {} \; find . -depth -iname "run*" -not -iname "*.yml" -exec rm -rf {} \;
find . -iname "mkimage*" -not -iname "*.yml" -exec rm -rf {} \; find . -depth -iname "mkimage*" -not -iname "*.yml" -exec rm -rf {} \;
rm -f disk.qcow2 tarball.img find . -depth -iname "disk.qcow2*" -not -iname "*.yml" -exec rm -rf {} \;
rm -f tarball.img
} }
trap clean_up EXIT trap clean_up EXIT

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh" . "${RT_PROJECT_ROOT}/_lib/lib.sh"
clean_up() { clean_up() {
find . -iname "test-sysctl*" -not -iname "*.yml" -exec rm -rf {} \; || true find . -depth -iname "test-sysctl*" -not -iname "*.yml" -exec rm -rf {} \;
} }
trap clean_up EXIT trap clean_up EXIT