Skip to content

Not able to connect to Firecracker VM from the pod #5105

Closed
@anubhavjana

Description

@anubhavjana

I have a deployment file which is meant to boot a firecracker VM on the pod. I have installed python and pip inside the ex4 filesystem. I want to execute the python script from the host / pod (either through CLI or inside yaml specification). The pod starts running, the curl requests are successful.

Here is a sample deployment file i am using:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: cnn-fc
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cnn-fc
  template:
    metadata:
      labels:
        app: cnn-fc
    spec:    
      hostPID: true  # Required for accessing /dev/kvm
      containers:
        - name: cnn-fc
          image: localhost:5000/ubuntu22.04-updated:latest
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true  # Firecracker needs KVM access          
          command: ["/bin/bash", "-c"]
          args:
            - |
              echo "-------- Starting Firecracker VM --------"
              SOCKET_PATH="/run/firecracker-${POD_NAME}.sock"
              rm -f $SOCKET_PATH  # Ensure no stale socket
              /usr/local/bin/firecracker --api-sock $SOCKET_PATH > /var/lib/firecracker.log 2>&1 &
              FC_PID=$!
              echo "Firecracker started with PID: $FC_PID on socket: $SOCKET_PATH"              

              # echo "-------- Checking Firecracker process --------"
              # ps aux | grep firecracker

              # Configure Firecracker VM
              echo "------- Configuring Firecracker boot source --------"
              curl --unix-socket $SOCKET_PATH -X PUT "http://localhost/boot-source" \
              -H "Content-Type: application/json" \
              -d '{
                      "kernel_image_path": "/var/lib/firecracker-containerd/runtime/hello-vmlinux.bin",
                      "boot_args": "console=ttyS0 reboot=k panic=1 pci=off selinux=0 quiet loglevel=0"
                  }' 

              

              # Attach root filesystem
              echo "-------- Attaching root filesystem --------"
              curl --unix-socket $SOCKET_PATH -X PUT "http://localhost/drives/rootfs" \
              -H "Content-Type: application/json" \
              -d '{
                      "drive_id": "rootfs",
                      "path_on_host": "/var/lib/firecracker-containerd/runtime/ubuntu-24.04.ext4",
                      "is_root_device": true,
                      "is_read_only": true
                  }'             

              echo "Root filesystem attached successfully!"             

              # Start VM
              echo "-------- Starting Firecracker VM --------"
              curl --unix-socket $SOCKET_PATH -X PUT "http://localhost/actions" \
              -H "Content-Type: application/json" \
              -d '{
                      "action_type": "InstanceStart"
                  }'
             
              echo "Firecracker VM started successfully!"

              tail -f /dev/null

          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name  # Unique socket per pod
          volumeMounts:
            - name: firecracker-socket
              mountPath: /run
            - name: firecracker-binary
              mountPath: /usr/local/bin/firecracker  
            - name: firecracker-images
              mountPath: /var/lib/firecracker-containerd/runtime  
            
      volumes:
        - name: firecracker-socket
          hostPath:
            path: /run
            type: Directory
        - name: firecracker-binary
          hostPath:
            path: /usr/local/bin/firecracker  # Firecracker binary on host
            type: File
        - name: firecracker-images
          hostPath:
            path: /var/lib/firecracker-containerd/runtime  # Kernel & RootFS images
            type: Directory

Please let me know what other information you need from my side. Please help.

Metadata

Metadata

Assignees

Labels

Status: Awaiting authorIndicates that an issue or pull request requires author action

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions