From b44639dfe0cdd87b8e6fae38a309333c770ed250 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Sun, 2 Jul 2017 22:24:08 -0700 Subject: [PATCH] add yamls and mods to accept various images --- Dockerfile | 6 ++---- kvm-rc-windows.yaml | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ kvm-rc.yaml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ kvm-windows.svc.yaml | 23 +++++++++++++++++++++++ scripts/build | 8 +------- scripts/start | 19 ++++++++++++------- 6 files changed, 133 insertions(+), 18 deletions(-) create mode 100644 kvm-rc-windows.yaml create mode 100644 kvm-rc.yaml create mode 100644 kvm-windows.svc.yaml diff --git a/Dockerfile b/Dockerfile index b0ef418..bbc3bf2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,6 @@ FROM ubuntu:16.10 MAINTAINER Dalton Hubble -ARG CL_CHANNEL -ARG CL_VERSION COPY scripts /scripts RUN /scripts/build -EXPOSE 2222 -ENTRYPOINT ["/scripts/start"] \ No newline at end of file +EXPOSE 2222 5900 +ENTRYPOINT ["/scripts/start"] diff --git a/kvm-rc-windows.yaml b/kvm-rc-windows.yaml new file mode 100644 index 0000000..bfa2a29 --- /dev/null +++ b/kvm-rc-windows.yaml @@ -0,0 +1,48 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: kvm-test-windows + labels: + k8s-app: kvm-test-windows +spec: + replicas: 1 + selector: + k8s-app: kvm-test-windows + template: + metadata: + labels: + k8s-app: kvm-test-windows + name: kvm-test-windows + spec: + terminationGracePeriodSeconds: 60 + containers: + - image: docker.barakmich.com/barak/k8s-kvm:latest + name: kvm-test-windows + imagePullPolicy: Always + securityContext: + privileged: true + ports: + - containerPort: 2222 + name: ssh + - containerPort: 5901 + name: vnc + env: + - name: VM_NAME + value: kvmtest + - name: VM_MEMORY + value: 2G + - name: DISK_IMG + value: /data/windows.img + - name: CD_IMG + value: /data/n-msws16.iso + args: + - -spice port=5901,password=testme + - -drive file=/data/virtio-win.iso,media=cdrom + volumeMounts: + - name: data + mountPath: /data + volumes: + - name: data + nfs: + server: "127.0.0.1" + path: "/fs/srv/k8skvm/windows" diff --git a/kvm-rc.yaml b/kvm-rc.yaml new file mode 100644 index 0000000..1744199 --- /dev/null +++ b/kvm-rc.yaml @@ -0,0 +1,47 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: kvm-test + labels: + k8s-app: kvm-test +spec: + replicas: 1 + selector: + k8s-app: kvm-test + template: + metadata: + labels: + k8s-app: kvm-test + name: kvm-test + spec: + terminationGracePeriodSeconds: 60 + containers: + - image: docker.barakmich.com/barak/k8s-kvm:latest + name: kvm-test + imagePullPolicy: Always + securityContext: + privileged: true + ports: + - containerPort: 2222 + name: ssh + - containerPort: 5900 + name: vnc + env: + - name: VM_NAME + value: kvmtest + - name: VM_MEMORY + value: 2G + - name: DISK_IMG + value: /data/ubuntu.img + - name: CD_IMG + value: /data/lubuntu-17.04-desktop-amd64.iso + args: + - -spice port=5900,password=testme + volumeMounts: + - name: data + mountPath: /data + volumes: + - name: data + nfs: + server: "127.0.0.1" + path: "/fs/srv/k8skvm" diff --git a/kvm-windows.svc.yaml b/kvm-windows.svc.yaml new file mode 100644 index 0000000..7ae540f --- /dev/null +++ b/kvm-windows.svc.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: Service +# Arbitrary Metadata block. Must have a name. +metadata: + name: kvm-windows + #labels: + #name: my-service +spec: + # Optionally, have a type. Valid options are ExternalName, ClusterIP, NodePort, and LoadBalancer + #type: NodePort + # + # Selector finds the target pod this service routes to. + selector: + name: kvm-test-windows + ports: + - port: 5901 + # service name for this port, must be a DNS label. + name: spice + # targetPort can be a name or a number on the pod that we're targeting + targetPort: 5901 + protocol: TCP + # If 'type: NodePort', which port to expose on all machines + #nodePort: 32378 diff --git a/scripts/build b/scripts/build index 26aa0f7..2b2dd1e 100755 --- a/scripts/build +++ b/scripts/build @@ -5,19 +5,13 @@ set -exu apt-get update apt-get install -y \ curl \ - bzip2 \ openssh-client \ qemu-kvm -URL="http://${CL_CHANNEL}.release.core-os.net/amd64-usr/${CL_VERSION}/coreos_production_qemu_image.img.bz2" -echo "Downloading Container Linux $CL_CHANNEL $CL_VERSION $URL" -curl -O $URL -bzip2 -d coreos_production_qemu_image.img.bz2 - curl -L https://github.com/coreos/container-linux-config-transpiler/releases/download/v0.3.0/ct-v0.3.0-x86_64-unknown-linux-gnu -o ct chmod +x ct apt-get remove -y curl bzip2 apt-get autoremove -y apt-get clean -rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ No newline at end of file +rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* diff --git a/scripts/start b/scripts/start index 0800bfc..3124418 100755 --- a/scripts/start +++ b/scripts/start @@ -1,11 +1,12 @@ #!/usr/bin/env bash set -eox pipefail -VM_NAME="${VM_NAME:-coreos-kvm}" +VM_NAME="${VM_NAME:-k8s-kvm}" VM_MEMORY="${VM_MEMORY:-4G}" -VM_DISK_SIZE="${VM_DISK_SIZE:-12G}" # hostfwd=[tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport HOSTFWD="${HOSTFWD:-hostfwd=tcp::2222-:22}" +DISK_IMG="${DISK_IMG:-./coreos_production_qemu_image.img}" +CD_ARG="" if [ -n "${CLOUD_CONFIG_FILE}" ]; then echo "Setting cloud config file: ${CLOUD_CONFIG_FILE}" @@ -32,7 +33,9 @@ if [ -n "$CONFIG_FILE" ]; then set -- -fw_cfg name=opt/com.coreos/config,file="${PWD}/ignition.json" "$@" fi -qemu-img resize ./coreos_production_qemu_image.img "${VM_DISK_SIZE}" +if [ -n "$CD_IMG" ]; then + CD_ARG="-drive file=${CD_IMG},media=cdrom" +fi # https://alpha.release.core-os.net/amd64-usr/current/coreos_production_qemu.sh qemu-system-x86_64 \ @@ -40,10 +43,12 @@ qemu-system-x86_64 \ -enable-kvm \ -cpu host \ -m "${VM_MEMORY}" \ - -net nic,model=virtio \ - -net user,"${HOSTFWD}",hostname="${VM_NAME}" \ - -drive if=virtio,file=./coreos_production_qemu_image.img \ + -device virtio-net,netdev=vmnic \ + -netdev user,id=vmnic,"${HOSTFWD}",hostname="${VM_NAME}" \ + -drive if=virtio,file="${DISK_IMG}" \ + ${CD_ARG} \ -nographic \ -machine accel=kvm \ + -vga std \ -smp 2 \ - "$@" + $@