63 - Linux VM - Deploy containers on MicroK8s

(Continue from 60 - Setup Linux VM on Digitalocean)



Running a basic nginx container to test that the cluster is indeed working

microk8s start
microk8s kubectl create deployment nginx-webserver --image=nginx
microk8s kubectl expose deployment nginx-webserver --type="NodePort" --port 80
microk8s kubectl get svc nginx-webserver # See random exposed port and access on browser


I want to try Dagger instead of creating Dockerfile, here’s the config for narze/heychat a NodeJS websocket server. Dagger enables building and pushing Docker images with TypeScript.

import { connect } from "@dagger.io/dagger"

  async (client) => {
    // use a node:18-slim container
    // mount the source code directory on the host
    // at /src in the container
    const source = client
      .withDirectory("/src", client.host().directory("."), {
        exclude: ["node_modules/", "ci/", "tmp/"],

    // set the working directory in the container
    // install application dependencies
    const runner = source
      .withExec(["yarn", "install", "--frozen-lockfile"])

    // build application
    // write the build output to the host
    const buildDir = runner.withExec(["yarn", "build"]).directory("./dist")

    await buildDir.export("./dist")

    const e = await buildDir.entries()

    console.log("build dir contents:\n", e)

    // use an node:18-slim container
    // copy the dist/ directory into the container filesystem
    // publish the resulting container to a registry
    const imageRef = await client
      .withDirectory("/app", buildDir)
      .withDirectory("/app/node_modules", runner.directory("./node_modules"))
      .withEntrypoint(["node", "/app/index.js"])
      .publish("ttl.sh/heychat-" + Math.floor(Math.random() * 10000000))
    console.log(`Published image to: ${imageRef}`)
  { LogOutput: process.stdout }

Run the code with node then the image will be built and pushed to ttl.sh, a temporary Docker image registry. Then I pull the image and run locally to see that it is working.

node ci/index.mjs

docker pull ttl.sh/heychat-8015391
docker run ttl.sh/heychat-8015391

docker ps # Verify that the container is working