• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Kubernetes | Hello Minikube
  1. Notes
  2. Create a deployment (default namespace)
  3. Create a service (default namespace)
  4. Expose the URL for a service using the minikube service command
  5. Expose the LoadBalancer external IP address using the minikube tunnel command
  6. Mount a host directory into Minikube using the minikube mount command

  1. Notes
    See this page for more details on how to use MiniKube: https://kubernetes.io/docs/tutorials/hello-minikube/
  2. Create a deployment (default namespace)
    • Create a deployment:
      $ kubectl create deployment echo-server --image=k8s.gcr.io/echoserver:1.4
      deployment.apps/echo-server created
    • View the deployment:
      $ kubectl get deployments
      NAME         READY   UP-TO-DATE   AVAILABLE   AGE
      echo-server  1/1     1            1           14s
    • View the pod:
      $ kubectl get pods
      NAME                          READY   STATUS    RESTARTS   AGE
      echo-server-7bf657c596-8l7r2  1/1     Running   0          27s
    • View the deployment's events:
      $ kubectl get events
      LAST SEEN   TYPE      REASON              OBJECT                              MESSAGE
      88s         Normal    Scheduled           pod/echo-server-7bf657c596-8l7r2    Successfully assigned default/echo-server-7bf657c596-8l7r2 to minikube
      87s         Normal    Pulling             pod/echo-server-7bf657c596-8l7r2    Pulling image "k8s.gcr.io/echoserver:1.4"
      82s         Normal    Pulled              pod/echo-server-7bf657c596-8l7r2    Successfully pulled image "k8s.gcr.io/echoserver:1.4"
      82s         Normal    Created             pod/echo-server-7bf657c596-8l7r2    Created container echoserver
      82s         Normal    Started             pod/echo-server-7bf657c596-8l7r2    Started container echoserver
      88s         Normal    SuccessfulCreate    replicaset/echo-server-7bf657c596   Created pod: echo-server-7bf657c596-8l7r2
      88s         Normal    ScalingReplicaSet   deployment/echo-server              Scaled up replica set echo-server-7bf657c596 to 1
  3. Create a service (default namespace)
    • Create a service:
      $ kubectl expose deployment echo-server --type=LoadBalancer --port=8080
      service/echo-server exposed
    • View the service:
      $ kubectl get services
      NAME         TYPE           CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
      echo-server  LoadBalancer   10.109.31.0   <pending>     8080:30617/TCP   39s
      kubernetes   ClusterIP      10.96.0.1     <none>        443/TCP          16h
  4. Expose the URL for a service using the minikube service command
    • Run the following command to expose the service (this will launch a browser and open the service's URL):
      $ minikube service echo-server
      |-----------|-------------|-------------|-----------------------------|
      | NAMESPACE |    NAME     | TARGET PORT |             URL             |
      |-----------|-------------|-------------|-----------------------------|
      | default   | echo-server |        8080 | http://192.168.99.100:30617 |
      |-----------|-------------|-------------|-----------------------------|
      🎉  Opening service default/echo-server in default browser...
      If you are using a remote shell to access Minikube's server, use the option --url=true to display the Kubernetes service URL instead of opening it in the browser:
      $ minikube service --url=true echo-server
      http://192.168.99.100:30617
    • Check the service endpoint:
      $ curl http://192.168.99.100:30617
      CLIENT VALUES:
      client_address=172.17.0.1
      command=GET
      real path=/
      query=nil
      request_version=1.1
      request_uri=http://192.168.99.100:8080/
      
      SERVER VALUES:
      server_version=nginx: 1.10.0 - lua: 10001
      
      HEADERS RECEIVED:
      accept=*/*
      host=192.168.99.100:30617
      user-agent=curl/7.58.0
      BODY:
      -no body in request-
  5. Expose the LoadBalancer external IP address using the minikube tunnel command
    Services of type LoadBalancer can be exposed using the minikube tunnel command:
    $ minikube tunnel
    [sudo] password for mtitek:
    Status:
        machine: minikube
        pid: 20303
        route: 10.96.0.0/12 -> 192.168.99.100
        minikube: Running
        services: [echo-server]
        errors:
            minikube: no errors
            router: no errors
            loadbalancer emulator: no errors
    Check the external IP of the LoadBalancer:
    $ kubectl get services
    NAME          TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)          AGE
    echo-server   LoadBalancer   10.101.184.172   10.101.184.172   8080:31571/TCP   92s
    kubernetes    ClusterIP      10.96.0.1        <none>           443/TCP          15m
    The external IP is exposed on the Minikube's host:
    $ curl http://10.101.184.172:8080
    CLIENT VALUES:
    client_address=192.168.99.1
    command=GET
    real path=/
    query=nil
    request_version=1.1
    request_uri=http://10.101.184.172:8080/
    
    SERVER VALUES:
    server_version=nginx: 1.10.0 - lua: 10001
    
    HEADERS RECEIVED:
    accept=*/*
    host=10.101.184.172:8080
    user-agent=curl/7.58.0
    BODY:
    -no body in request-
    The minikube tunnel command should be kept running in a terminal window to keep the external IP of the LoadBalancer exposed. You can enter Ctrl-C to stop exposing the external IP and clean up the network routes. This will also clean up the file ~/.minikube/tunnels.json file:
    $ cat ~/.minikube/tunnels.json | jq '.'
    [
      {
        "Route": {
          "Gateway": "192.168.99.100",
          "DestCIDR": {
            "IP": "10.96.0.0",
            "Mask": "//AAAA=="
          },
          "ClusterDomain": "cluster.local",
          "ClusterDNSIP": "10.96.0.10"
        },
        "MachineName": "minikube",
        "Pid": 20303
      }
    ]
    In some cases, if Ctrl-C didn't work properly, you can force cleaning up all orphaned routes left in ~/.minikube/tunnels.json file file:
    $ minikube tunnel --cleanup=true
  6. Mount a host directory into Minikube using the minikube mount command
    minikube mount usage:
    $ minikube mount --help
    Mounts the specified directory into minikube.
    
    Options:
          --uid='docker': Default user id used for the mount
          --gid='docker': Default group id used for the mount
          --mode=493: File permissions used for the mount
    
          --options=[]: Additional mount options, such as cache=fscache
          --ip='': Specify the ip that the mount should be setup on
          --kill=false: Kill the mount process spawned by minikube start
    
          --type='9p': Specify the mount filesystem type (supported types: 9p)
          --9p-version='9p2000.L': Specify the 9p version that the mount should use
          --msize=262144: The number of bytes to use for 9p packet payload
    
    Usage:
      minikube mount [flags] <source directory>:<target directory> [options]
    
    Use "minikube options" for a list of global command-line options (applies to all commands).
    To allow containers running in Minikube to read/write from/into the host directory, you have to set properly the following options uid, gid, mode.

    Let's say the current user in the host has the uid "1000" and gid "1000":
    $ id
    uid=1000(mtitek) gid=1000(mtitek) groups=1000(mtitek)
    Let's also say that the Dockerfile is running using the same uid and gid of the host's user:
    FROM ubuntu:20.04
    
    RUN groupadd -r tek --gid=1000 && useradd -r -g tek --uid=1000 mti
    
    USER mti
    
    VOLUME /myvol
    To mount a local directory from the host into the Minikube, you use the following command:
    $ minikube mount /opt/data:/mtm/myvol --uid=1000 --gid=1000 --mode=0777
© 2025  mtitek