Which issue(s) this PR fixes(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #95
Fixes #34
Fixes #112
Now, we’ll create the IPAddressPool and the L2Advertisement custom resources. The script below creates the CRs with the right addresses, that match to the kind cluster addresses:
k get cluster
NAME CLUSTERCLASS PHASE AGE VERSION
my-cluster kubevirt-alpha-1-29-v0-sha.n24nerk Provisioned 3s v1.29.5
k get vm
NAME AGE STATUS READY
my-cluster-alpha-9t2pf-jq4d8-rpvf9 8m56s Running True
my-cluster-dmkh2-d7jfc 11m Running True
Install cloud-provider-kubevirt
get kubeconfig of workload cluster
clusterctl get kubeconfig my-cluster > my-cluster.kubeconfig
create secret to pass kubeconfig of workload cluster into cloud-provider-kubevirt pod
# Clone repo first
git clone https://github.com/kubevirt/cloud-provider-kubevirt.git
cd cloud-provider-kubevirt/config/base
# It is necessary to have kustomize installed (https://kustomize.io/)
# kustomize.yaml file is deprecated
kustomize edit fix --vars
# Apply kustomize.yaml file
kubectl apply -k .
patch cloud-provider-kubevirt deployment
# Retrieve the current args of the container
CURRENT_ARGS=$(kubectl get deployment kubevirt-cloud-controller-manager -n default -o=jsonpath='{.spec.template.spec.containers[0].args}')
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
a008600cad34b477ca41aad89296a563 LoadBalancer 10.96.68.186 172.18.255.201 80:32062/TCP 15s
kubernetes ClusterIP 10.96.0.1 443/TCP 36m
my-cluster-lb LoadBalancer 10.96.235.163 172.18.255.200 6443:30745/TCP 11m
curl 172.18.255.201
<!DOCTYPE html>
Welcome to nginx!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
11. If you want to install CSI KubeVirt driver, follow these steps:
- enable it in `cluster.yaml` file via variables, see example of it in step 8
- install Containerized Data Importer (CDI)
export VERSION=$(basename $(curl -s -w %{redirect_url} https://github.com/kubevirt/containerized-data-importer/releases/latest))
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator.yaml
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-cr.yaml
```
- clone csi-driver repository
```
git clone https://github.com/kubevirt/csi-driver.git
```
- deploy service account on infra cluster(must be deployed in the namespace of the tenant cluster inside of the infra cluster)
```
kubectl apply -f csi-driver/deploy/infra-cluster-service-account.yaml
```
- add the namespace where the tenant cluster is deployed to the `kustomization.yaml` file
```
sed -i '1i\namespace: default' csi-driver/deploy/controller-infra/base/kustomization.yaml
```
- create secret `kvcluster-kubeconfig`
```
kubectl create secret generic kvcluster-kubeconfig --from-file=value=my-cluster.kubeconfig
```
- create configmap `driver-config`
```
kubectl apply -f - << EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: driver-config
data:
infraClusterNamespace: default
infraClusterLabels: csi-driver/cluster=my-cluster
infraStorageClassEnforcement: |
allowAll: true
allowDefault: true
EOF
```
- deploy the controller resources in the infra cluster(adjust `image` field to `registry.dnation.cloud/test-mg/kubevirt-csi-driver:latest` for `csi-driver` container in `deploy/controller-infra/base/deploy.yaml` file)
```
kubectl apply --kustomize csi-driver/deploy/controller-infra/base
```
$ k get pvc --kubeconfig my-cluster.kubeconfig
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
1g-kubevirt-disk Bound pvc-0090496c-62a0-4112-9354-67591e49977f 1Gi RWO kubevirt 107s
$ k get pv --kubeconfig my-cluster.kubeconfig
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE
pvc-0090496c-62a0-4112-9354-67591e49977f 1Gi RWO Delete Bound default/1g-kubevirt-disk kubevirt 114s
What this PR does / why we need it:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged): Fixes #95 Fixes #34 Fixes #112Special notes for your reviewer:
See docs https://cluster-api.sigs.k8s.io/user/quick-start.html?highlight=management and https://kubevirt.io/quickstart_kind/
I created Ubuntu instance in gx-scs - flavor SCS-16V:32:100
Create KinD cluster with config like
Install the CNI based on your preferences - https://cluster-api.sigs.k8s.io/user/quick-start.html?highlight=management#install-the-calico-cni
Install KubeVirt on the kind cluster
Deploy CAPI/CAPK/CSO
INstall MetalLB for loadbalancing
Now, we’ll create the IPAddressPool and the L2Advertisement custom resources. The script below creates the CRs with the right addresses, that match to the kind cluster addresses:
Create Cluster Stack
Create cluster
Install cloud-provider-kubevirt
create configmap with cloud-config like
Append the cluster-name argument into container
NEW_ARGS=$(jq --argjson arg_array '["--cluster-name=my-cluster"]' \ --argjson current_args "$CURRENT_ARGS" \ '$current_args + $arg_array' <<< '[]')
Apply the updated args to the deployment
kubectl patch deployment kubevirt-cloud-controller-manager -n default --type=json \ -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/args", "value": '"$NEW_ARGS"'}]'
Test loadbalancing by creating a simple nginx deployment on workload cluster
check if svc in kind cluster was created
kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE a008600cad34b477ca41aad89296a563 LoadBalancer 10.96.68.186 172.18.255.201 80:32062/TCP 15s kubernetes ClusterIP 10.96.0.1 443/TCP 36m
my-cluster-lb LoadBalancer 10.96.235.163 172.18.255.200 6443:30745/TCP 11m
curl 172.18.255.201 <!DOCTYPE html>
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
$ k get pvc --kubeconfig my-cluster.kubeconfig NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE 1g-kubevirt-disk Bound pvc-0090496c-62a0-4112-9354-67591e49977f 1Gi RWO kubevirt 107s
$ k get pv --kubeconfig my-cluster.kubeconfig
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE
pvc-0090496c-62a0-4112-9354-67591e49977f 1Gi RWO Delete Bound default/1g-kubevirt-disk kubevirt 114s