Prerequisites:
cat <<EOF > /tmp/kind.yml && kind create cluster --config /tmp/kind.yml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: kubevirt-ssh-testing
networking:
apiServerAddress: "127.0.0.1"
apiServerPort: 6443
nodes:
- role: control-plane
image: kindest/node:v1.23.0
extraPortMappings:
- containerPort: 30950
hostPort: 30950
EOF
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/v0.48.1/kubevirt-operator.yaml
kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/v0.48.1/kubevirt-cr.yaml
- Wait for deployment status
Done
(may take a few minutes)
watch kubectl get kubevirt.kubevirt.io/kubevirt -n kubevirt -o=jsonpath="{.status.phase}"
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Service
metadata:
name: testvm-ssh
spec:
ports:
- nodePort: 30950
port: 30950
protocol: TCP
targetPort: 22
selector:
test: kmi
type: NodePort
---
apiVersion: kubevirt.io/v1alpha3
kind: VirtualMachine
metadata:
name: testvm
labels:
test: kmi
spec:
running: true
template:
metadata:
labels:
test: kmi
spec:
domain:
devices:
autoattachPodInterface: true
autoattachSerialConsole: true
autoattachGraphicsDevice: true
disks:
- name: containerdisk
bootOrder: 1
disk:
bus: virtio
- name: cloudinitdisk
disk:
bus: virtio
resources:
limits:
memory: 2G
requests:
memory: 2G
volumes:
- name: containerdisk
containerDisk:
image: quay.io/containerdisks/fedora:35
imagePullPolicy: IfNotPresent
- name: cloudinitdisk
cloudInitNoCloud:
userData: |
#cloud-config
chpasswd:
expire: False
list: |
fedora:fedora
users:
- name: fedora
shell: /bin/bash
lock_passwd: false
groups: sudo,wheel
sudo: ['ALL=(ALL) NOPASSWD:ALL']
ssh-authorized-keys:
- $(cat ~/.ssh/id_rsa.pub)
EOF
- Wait for testvm state "running"
watch kubectl get vmi testvm -o=jsonpath="{.status.phase}"
- You can login to this vm with user:pass fedora:fedora
- Exit the serial console with ctrl+shift+]
virtctl console testvm
virtctl vnc testvm
ssh -p 30950 fedora@127.0.0.1
- Troubleshooting Commands
kubectl describe vm testvm
kubectl describe vmi testvm
kubectl get vmi testvm -owide
kubectl describe svc testvm-ssh
- Run using emulation instead of hardware virtualization
kubectl create configmap kubevirt-config -n kubevirt --from-literal debug.useEmulation=true