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-master.sh
./boot.sh
```
Get IP address of the master:
@ -36,12 +36,12 @@ and try `kubectl get nodes` from within the master.
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:
```
shell1> ./boot-node.sh 1 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell2> ./boot-node.sh 2 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell3> ./boot-node.sh 3 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell1> ./boot.sh 1 --token bb38c6.117e66eabbbce07d 192.168.65.22:6443
shell2> ./boot.sh 2 --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"
cmdline: "console=ttyS0 console=tty0 page_poison=1"
init:
- linuxkit/init:1b8a7e394d2ec2f1fdb4d67645829d1b5bdca037
- linuxkit/init:2599bcd5013ce5962aa155ee8929c26160de13bd
- linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f
- linuxkit/containerd:b50181bc6e0084e5fcd6b6ad3cf433c4f66cae5a
- linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d
@ -25,6 +25,10 @@ onboot:
- /dev:/dev
- /var:/var:rshared,rbind
services:
- name: getty
image: "linuxkit/getty:148946d72d1c96df3ea91cb8ee4f9583cd3cc5c2"
env:
- INSECURE=true
- name: rngd
image: "linuxkit/rngd:1fa4de44c961bb5075647181891a3e7e7ba51c31"
- name: dhcpcd

View File

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

View File

@ -20,11 +20,12 @@ const QemuImg = "linuxkit/qemu:c9691f5c50dd191e62b77eaa2f3dfd05ed2ed77c"
// QemuConfig contains the config for Qemu
type QemuConfig struct {
Path string
ISO bool
ISOBoot bool
UEFI bool
Kernel bool
GUI bool
Disks Disks
MetadataPath string
FWPath string
Arch string
CPUs string
@ -55,9 +56,13 @@ func runQemu(args []string) {
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")
// State flags
state := flags.String("state", "", "Path to directory to keep VM state in")
// Paths and settings for disks
var disks Disks
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
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 {
id := ""
if i != 0 {
@ -119,7 +153,8 @@ func runQemu(args []string) {
d.Format = "qcow2"
}
if d.Size != 0 && d.Path == "" {
d.Path = prefix + "-disk" + id + ".img"
mkstate()
d.Path = filepath.Join(*state, "disk"+id+".img")
}
if d.Path == "" {
log.Fatalf("disk specified with no size or name")
@ -134,13 +169,18 @@ func runQemu(args []string) {
disks = append(d, disks...)
}
if *isoBoot && isoPath != "" {
log.Fatalf("metadata and ISO boot currently cannot coexist")
}
config := QemuConfig{
Path: path,
ISO: *isoBoot,
ISOBoot: *isoBoot,
UEFI: *uefiBoot,
Kernel: *kernelBoot,
GUI: *enableGUI,
Disks: disks,
MetadataPath: isoPath,
FWPath: *fw,
Arch: *arch,
CPUs: *cpus,
@ -214,19 +254,21 @@ func runQemuContainer(config QemuConfig) error {
}
var binds []string
if filepath.IsAbs(config.Path) {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(config.Path)))
addBind := func(p string) {
if filepath.IsAbs(p) {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(p)))
} else {
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 {
if filepath.IsAbs(d.Path) {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", filepath.Dir(d.Path)))
} else {
binds = append(binds, "-v", fmt.Sprintf("%[1]s:%[1]s", cwd))
}
addBind(d.Path)
}
var args []string
@ -314,7 +356,7 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
for i, d := range config.Disks {
index := i
// hdc is CDROM in qemu
if i >= 2 && config.ISO {
if i >= 2 && config.ISOBoot {
index++
}
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, "-boot", "d")
} else if config.MetadataPath != "" {
qemuArgs = append(qemuArgs, "-cdrom", config.MetadataPath)
}
if config.UEFI {

View File

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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

@ -13,7 +13,7 @@ IMAGE_NAME="kmod-test"
clean_up() {
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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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

View File

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

View File

@ -10,7 +10,7 @@ set -e
. "${RT_PROJECT_ROOT}/_lib/lib.sh"
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