Skip to content

devniel/spots

Repository files navigation

Spots

An example monorepo project with local kubernetes deployment done on weekends since July until mid November 2020.

(These steps only apply to my environment, a guide will be publish once my blog engine is updated)

Before running, start the Ubuntu Server hosted on Hyper-V, minikube will start automatically, otherwise run the following command:

minikube start --insecure-registry "0.0.0.0/0"

Start the proxy that serves minikube on the port 8001 of the Ubuntu Server:

kubectl proxy --address='0.0.0.0' --disable-filter=true

Expose the local registry server:

 kubectl port-forward -n kube-system $(kubectl get po -n kube-system | grep registry-wnppn | \awk '{print $1;}') 5000:5000 --address 0.0.0.0

The pods related to spots, already deployed, should be exposed with port-forwarding; first we get the pod names:

 kubectl get po -n=spots
NAME                         READY   STATUS    RESTARTS   AGE
spots-api-765999c867-mkz6s   1/1     Running   0          24d
spots-ui-5b584bb8b9-cfsw7    1/1     Running   0          24d

Then we apply the port-forwarding:

kubectl port-forward -n spots $(kubectl get po -n spots | grep spots-api-765999c867-mkz6s | \awk '{print $1;}') 3333:3333 --address 0.0.0.0

On windows, open Powershell with admin permissions, then apply the WSL Forwarding:

Enable-WSLForward

If you open $PROFILE, the described command is related to the following function:

function Enable-WSLForward {
 Get-NetIPInterface | where {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)' -or $_.InterfaceAlias -eq 'vEthernet (Ubuntu-VMSwitch)'} | Set-NetIPInterface -Forwarding Enabled
 Write-Output "Forwarding enabled, printing interfaces..."
 Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | Sort-Object -Property IfIndex | Format-Table
}

After that, open your Ubuntu (WSL 2) environment, then apply the context to kube-ctl.

kubectl config use-context ubuntu-hyper-v

* The context has the following configuration:

apiVersion: v1
clusters:
- cluster:
    server: http://ubuntu-vm:8001
  name: ubuntu-hyper-v
contexts:
- context:
    cluster: ubuntu-hyper-v
    user: devniel
  name: ubuntu-hyper-v
current-context: ubuntu-hyper-v
kind: Config
preferences: {}

* The /etc/hosts has the following config:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost

192.168.1.15    host.docker.internal
192.168.1.15    gateway.docker.internal
127.0.0.1       kubernetes.docker.internal
192.168.0.2     ubuntu-vm
192.168.0.2     ubuntu-vm.registry.local

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Then open the directory of the monorepo and run the skaffold config with:

skaffold dev --port-forward

If everything works fine then the tail of the output should be:

Deployments stabilized in 5.2152523s
Port forwarding service/spots-api in namespace spots, remote port 3333 -> address 127.0.0.1 port 3333
Port forwarding service/spots-ui in namespace spots, remote port 3000 -> address 127.0.0.1 port 3000
Press Ctrl+C to exit
Watching for changes...
[wait-for-dependent-service] Waiting up to 600 seconds for HTTP 200 from http://spots-api.spots.svc.cluster.local:3333/api/hello
[wait-for-dependent-service] OK
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   [NestFactory] Starting Nest application...
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   [InstanceLoader] AppModule dependencies initialized +13ms
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   [RoutesResolver] AppController {/api}: +7ms
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   [RouterExplorer] Mapped {/api/hello, GET} route +3ms
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   [NestApplication] Nest application successfully started +2ms
[spots-api] [Nest] 1   - 12/21/2020, 7:47:55 PM   Listening at http://localhost:3333/api +4ms
[spots-ui] /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
[spots-ui] /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
[spots-ui] /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
[spots-ui] 10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
[spots-ui] 10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
[spots-ui] /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
[spots-ui] /docker-entrypoint.sh: Configuration complete; ready for start up

Openning the http://localhost:3000 on the host (Windows 10) shows up the project.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors