이 실습에서는..

kubevirt를 통해 생성한 VM pod 내에 설치한 Kuberentes cluster에 nginx server를 설치하고 외부에서 접근하자

가정

Parent Cluster에 VM을 생성했다.

image.png

virtctl console test-vm -n shelley 을 통해 ssh로 접속하여 VM내에 K8s cluster를 설치했다.

image.png

이 cluster(Child Cluster)에 nginx deployment 및 service를 통해 Expose했다.

kubectl apply -n shelley -f - <<EOF
apiVersion: v1
kind: Service
metadata:
  name: nginxsvc
  labels:
    app: nginx
spec:
  type: NodePort
  ports:
  - port: 80
    protocol: TCP
    nodePort: 31111
    name: http
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
          name: http
EOF

31111 port로 배포된 것을 확인

image.png

Parent Cluster에서 Child Cluster Service에 접근하기

Parent Cluster에 Service 배포

kubectl apply -n shelley -f - <<EOF
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  ports:
  - protocol: TCP
    port: 31111
    targetPort: 31111
  selector:
    **vm.kubevirt.io/name: test-vm**
EOF

30259 NodePort로 배포된 것을 확인

image.png

브라우저에서 http://<parent-control-plane-node-ip>:30259 로 접근하면 아래와 같은 화면이 뜨는지 확인

image.png