Skip to content

Instantly share code, notes, and snippets.

@usrbinkat
Last active May 12, 2022 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usrbinkat/fc1028245d28cfabc6ade540b350ed8c to your computer and use it in GitHub Desktop.
Save usrbinkat/fc1028245d28cfabc6ade540b350ed8c to your computer and use it in GitHub Desktop.
Boot Kubevirt VM on Kind Kubernetes in Docker
curl -Lo /tmp/kind https://kind.sigs.k8s.io/dl/v0.13.0/kind-linux-amd64
sudo install -o root -g root -m 0755 /tmp/kind /usr/local/bin/kind

curl --output /tmp/virtctl -L https://github.com/kubevirt/kubevirt/releases/download/$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | awk -F '[",]' '/tag_name/{print $4}')/virtctl-$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | awk -F '[",]' '/tag_name/{print $4}')-linux-amd64
sudo install -o root -g root -m 0755 /tmp/virtctl /usr/local/bin/virtctl

cat <<EOF > /tmp/kind.yaml && kind create cluster --config /tmp/kind.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: core
networking:
  apiServerAddress: "0.0.0.0"
  apiServerPort: 6443
nodes:
  - role: control-plane
  - role: worker
    extraPortMappings:
    - containerPort: 30950
      hostPort: 30950
EOF

helm repo add jetstack https://charts.jetstack.io; helm repo update
helm upgrade --install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true

curl -sL https://github.com/kubevirt/kubevirt/releases/download/$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | awk -F '[",]' '/tag_name/{print $4}')/kubevirt-operator.yaml | kubectl apply -f -
curl -sL https://github.com/kubevirt/kubevirt/releases/download/$(curl -s https://api.github.com/repos/kubevirt/kubevirt/releases/latest | awk -F '[",]' '/tag_name/{print $4}')/kubevirt-cr.yaml | kubectl apply -f -
kubectl -n kubevirt wait kv kubevirt --for condition=Available

curl -L https://gist.githubusercontent.com/usrbinkat/fc1028245d28cfabc6ade540b350ed8c/raw/95e2373579127a2837051c8d1b3deb160e97be93/rhcos.kubevirt.yaml.sh | bash
kubectl apply -f /tmp/core.kubevirt.yaml
virtctl console core

ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no -p30950 127.0.0.1

Current:

firmware:
  kernelBoot:
    container:
      image: quay.io/containerdisks/rhcos:4.10-kernelboot
      imagePullPolicy: IfNotPresent
      initrdPath: /var/boot/initramfs
      kernelPath: /var/boot/vmlinuz
    kernelArgs: console=ttyS0 initrd=main coreos.live.rootfs_url=https://local.registry.com:5000/v2/coreos/blobs/sha256:ca156c81c678a7a537ec68fc34187646f4893fd0e5747bb15b31b83b837c8b6e

Proposed:

firmware:
  kernelBoot:
    container:
      pullPolicy: IfNotPresent
      initrdPath: https://local.registry.com:5000/v2/coreos/blobs/sha256:d0e091121232aed1c436b818e285a1da7fdcaee92b34c2166dc5e3f344d6eb1f
      kernelPath: https://local.registry.com:5000/v2/coreos/blobs/sha256:ac0ee21103bf5c186181792eff7aedb123f5875967b5cdef85dd27c31901d583
    kernelArgs: console=ttyS0 initrd=main coreos.live.rootfs_url=https://local.registry.com:5000/v2/coreos/blobs/sha256:ca156c81c678a7a537ec68fc34187646f4893fd0e5747bb15b31b83b837c8b6e
cat <<EOF > /tmp/core.kubevirt.yaml
---
apiVersion: v1
kind: Service
metadata:
name: core-ssh
spec:
ports:
- nodePort: 30950
port: 30950
protocol: TCP
targetPort: 22
selector:
app: core
type: NodePort
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstancePreset
metadata:
name: c1m1
spec:
selector:
matchLabels:
kubevirt.io/flavor: c1m1
domain:
devices:
autoattachPodInterface: true
autoattachSerialConsole: true
autoattachGraphicsDevice: true
networkInterfaceMultiqueue: false
cpu:
cores: 1
threads: 1
sockets: 1
model: host-model
resources:
requests:
memory: 1G
---
apiVersion: kubevirt.io/v1
kind: VirtualMachineInstance
metadata:
name: core
labels:
app: core
kubevirt.io/flavor: c1m1
spec:
domain:
devices:
disks:
- name: containerdisk
bootOrder: 1
disk:
bus: virtio
- name: cloudinitdisk
disk:
bus: virtio
hostname: core
terminationGracePeriodSeconds: 0
volumes:
- name: containerdisk
containerDisk:
image: quay.io/containerdisks/rhcos:4.10
imagePullPolicy: IfNotPresent
- name: cloudinitdisk
cloudInitConfigDrive:
userData: |-
{
"ignition": {
"version": "3.3.0"
},
"passwd": {
"users": [
{
"name": "$(whoami)",
"sshAuthorizedKeys": [
"$(cat ~/.ssh/id_rsa.pub)"
]
}
]
}
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment