Cannot run start an VM using KubeVirt with GKE

Viewed 708

Currently I try to use KubeVirt with GKE cluster.

What I have done (follow the official document):

  1. Create a GKE cluster with 3 nodes via GCP console
  2. Install kubectl locally and connect to this cluster
  3. Install kubevirt via kubectl
  4. Install virtctl locally
  5. set debug.useEmulation to true
  6. create the testvm (follow the demo) All the steps above work fine.

But now I have troubles to start the vm

  1. If I try to start it via "virtctl start testvm", I get the following error message:

"Error starting VirtualMachine the server has asked for the client to provide credentials"

  1. If I try to modify the VM template to set it running by default, it doesn't work either.In the virt-launcher pod, the compute container starts successfully but the volumecontainerdisk fails, with the following log:
standard_init_linux.go:211: exec user process caused "permission denied"

Any help is appreciated, thanks.

2 Answers

It seems there are issues with the default GKE auth method when connecting from local to a cluster when using gcloud container clusters get-credentials....

What worked for me is creating a new SA and creating a kubeconfig for it:

{
kubectl create sa deployer
kubectl create clusterrolebinding deployer --clusterrole cluster-admin --serviceaccount default:deployer

KUBE_DEPLOY_SECRET_NAME=`kubectl get sa deployer -o jsonpath='{.secrets[0].name}'`
KUBE_API_EP=`kubectl get ep -o jsonpath='{.items[0].subsets[0].addresses[0].ip}'`
KUBE_API_TOKEN=`kubectl get secret $KUBE_DEPLOY_SECRET_NAME -o jsonpath='{.data.token}'|base64 --decode`
KUBE_API_CA=`kubectl get secret $KUBE_DEPLOY_SECRET_NAME -o jsonpath='{.data.ca\.crt}'|base64 --decode`
echo $KUBE_API_CA > tmp.deploy.ca.crt

export KUBECONFIG=./my-new-kubeconfig
kubectl config set-cluster k8s --server=https://$KUBE_API_EP --certificate-authority=tmp.deploy.ca.crt --embed-certs=true
kubectl config set-credentials k8s-deployer --token=$KUBE_API_TOKEN
kubectl config set-context k8s --cluster k8s --user k8s-deployer
kubectl config use-context k8s

rm tmp.deploy.ca.crt
unset KUBECONFIG
}

kubectl virt start testvm --kubeconfig ./my-new-kubeconfig

More explanation: https://faun.pub/manually-connect-to-your-kubernetes-cluster-from-the-outside-d852346a7f0a

You can start vm without virtctl by updating VM's manifest using kubectl

kubectl patch virtualmachine testvm --type merge -p '{"spec":{"running":true}}'
Related