-
Notifications
You must be signed in to change notification settings - Fork 0
kubevirt on datacenter
Allan Roger Reid edited this page May 2, 2024
·
4 revisions
If images don't already exist, request CDI installation from admin - https://kubevirt.io/user-guide/operations/containerized_data_importer/
export TAG=$(curl -s -w %{redirect_url} https://github.com/kubevirt/containerized-data-importer/releases/latest)
export VERSION=$(echo ${TAG##*/})
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/v1.59.0/cdi-operator.yaml
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-cr.yaml
kubectl -n cdi get all
kubectl create namespace vm-images
kubectl port-forward -n cdi service/cdi-uploadproxy 18443:443
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
virtctl image-upload dv ubuntu-cloud-base --namespace=vm-images --size=5Gi --image-path=/home/allan/kubevirt/jammy-server-cloudimg-amd64.img --uploadproxy-url=https://127.0.0.1:18443 --access-mode=ReadWriteOnce --volume-mode=filesystem --insecure --force-bind
Optionally, also request the installation of a DataImportCron - https://github.com/kubevirt/containerized-data-importer/blob/main/doc/os-image-poll-and-update.md
kubectl -n vms get datasource
NAME AGE
ubuntu-2204 139d
Recreate vm. Note Fedora images already come with a qemu-guest-agent
, simplifying the addition of public key access thru a k8s secret
kubectl delete virtualmachine.kubevirt.io/ubuntu-cloud-base-lab-0 -n vms
cat << EOF > ubuntu-cloud-base-lab-0.yaml
apiVersion: kubevirt.io/v1
kind: VirtualMachine
metadata:
labels:
min.io/vm: ubuntu-cloud-base-lab-0
name: ubuntu-cloud-base-lab-0
namespace: vms
spec:
running: false
template:
metadata:
labels:
min.io/vm: ubuntu-cloud-base-lab-0
spec:
architecture: amd64
domain:
devices:
disks:
- disk:
bus: virtio
name: os
resources:
requests:
memory: 4096M
volumes:
- dataVolume:
name: ubuntu-cloud-base-disk
name: os
- cloudInitNoCloud:
userData: |
#cloud-config
ssh_authorized_keys:
- ecdsa-sha2-nistp256 abc123
user: ubuntu
name: cloudinitdisk
dataVolumeTemplates:
- metadata:
name: ubuntu-cloud-base-disk
spec:
pvc:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
sourceRef:
kind: DataSource
name: ubuntu-2204
EOF
kubectl create -f ubuntu-cloud-base-lab-0.yaml
virtctl
VERSION=$(kubectl get kubevirt.kubevirt.io/kubevirt -n vms -o=jsonpath="{.status.observedKubeVirtVersion}")
VERSION=v1.2.0
ARCH=$(uname -s | tr A-Z a-z)-$(uname -m | sed 's/x86_64/amd64/') || windows-amd64.exe
echo ${ARCH}
echo https://github.com/kubevirt/kubevirt/releases/download/$VERSION/virtctl-$VERSION-$ARCH
curl -L -o virtctl https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/virtctl-${VERSION}-${ARCH}
mv virtctl-v1.2.0-darwin-arm64 virtctl
mv virtctl-v1.1.0-darwin-arm64 virtctl
chmod +x virtctl
kubectl -n vms describe datavolume ubuntu-cloud-base-disk
kubectl -n vms get datavolume ubuntu-cloud-base-disk
kubectl -n vms get pvc
./virtctl -n vms start ubuntu-cloud-base-lab-0
kubectl -n vms get vm/ubuntu-cloud-base-lab-0 -w
./virtctl -n vms console ubuntu-cloud-base-lab-0
cat << EOF > ubuntu-cloud-base-lab-0-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: ubuntu-cloud-base-lab-0
namespace: vms
spec:
ports:
- name: ssh
nodePort: 30022
port: 22
protocol: TCP
targetPort: 22
selector:
min.io/vm: ubuntu-cloud-base-lab-0
sessionAffinity: None
type: NodePort
EOF
kubectl create -f ubuntu-cloud-base-lab-0-nodeport.yaml
kubectl -n vms get svc
ssh -i /Users/allanreid/.ssh/id_ecdsa ubuntu@1.2.3.4 -p 30022 -o ServerAliveInterval=5 -o "ServerAliveCountMax 100000" -o "StrictHostKeyChecking=off"
or
./virtctl -n vms ssh -i /Users/allanreid/.ssh/id_ecdsa ubuntu@ubuntu-cloud-base-lab-0 -p 22 --local-ssh-opts="-o StrictHostKeyChecking=off" --local-ssh=true