K8s/Localtunnel

From Chorke Wiki
Revision as of 12:16, 24 October 2025 by Shahed (talk | contribs) (K8s » Infra)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

K8s » Config

K8s » Config

Context » Available

Context » Enabled

export KUBECONFIG=${HOME}/.kube/shahed-aa-kubeconfig.yaml
export KUBECONFIG=${HOME}/.kube/shahed-ab-kubeconfig.yaml
export KUBECONFIG=${HOME}/.kube/shahed-ac-kubeconfig.yaml
k9s  --kubeconfig ${HOME}/.kube/shahed-ab-kubeconfig.yaml -A
export KUBECONFIG=${HOME}/.kube/shahed-ab-kubeconfig.yaml
kubectl config view -o=yaml|yq '.contexts[0].name'
export KUBECONFIG=${HOME}/.kube/aws-kubeconfig.yaml
export KUBECONFIG=${HOME}/.kube/dev-kubeconfig.yaml
export KUBECONFIG=${HOME}/.kube/gcp-kubeconfig.yaml
export KUBECONFIG=${HOME}/.kube/lke-kubeconfig.yaml
kubectl config get-contexts
kubectl get    ns|grep localtunnel
kubectl create ns      localtunnel||true
k9s  --kubeconfig ${HOME}/.kube/shahed-ab-kubeconfig.yaml -n localtunnel

K8s » Infra

Infra » LocalTunnel

LocalTunnel » Search

docker search node --filter stars=3 --filter is-official=true --no-trunc
docker search node --filter stars=3 --filter is-official=true 
docker search node --filter stars=3 --no-trunc --limit=10
docker search node --filter stars=3 --no-trunc
docker search node --filter stars=3 --limit=10
docker search node --filter stars=3
docker pull node:25.0-alpine
docker pull node:20.19-alpine
docker pull node:25.0-bullseye
docker pull node:20.19-bullseye
docker pull node:25.0-bookworm
docker pull node:20.19-bookworm
echo;\
FETCH_SIZE=30;\
IMAGE_NAME=node;\
curl -fsSL "https://registry.hub.docker.com/v2/repositories/library/${IMAGE_NAME}/tags?page_size=${FETCH_SIZE}" \
 | jq -r '.results[]|select(.name != null and .name != "" and .name != "unknown")
 | {tag: .name, digest: (.digest | sub("^sha256:"; "")[:12]), arch: (.images[0].architecture // "n/a"), sizeMB: ((.full_size / 1048576) | round)}
 | [.tag, .digest, .arch, (.sizeMB | tostring + " MB")]| @tsv' | sort -V \
 | awk -F'\t' '{printf "%-25s %-14s %-10s %-8s\n", $1, $2, $3, $4}'

LocalTunnel » Config

cat <<'ENV'| \
kubectl -n localtunnel create configmap localtunnel --from-env-file=/dev/stdin
LC_ALL=C.UTF-8
TZ=UTC-8
PORT=80
LT_PRINT_REQUESTS=--print-requests
LT_HOST=https://localtunnel.me
LT_SUBDOMAIN=pihole-shahed
LOCAL_HOST=192.168.49.110
ENV
cat <<ENV | \
kubectl -n localtunnel create secret generic localtunnel --from-env-file=/dev/stdin
LT_PASSWORD=$(curl -fsSL https://ipv4.icanhazip.com | tr -d '\n')
ENV
cat << YML| \
kubectl -n localtunnel \
 patch  secret localtunnel --type merge --patch-file=/dev/stdin
---
data:
  LT_PASSWORD: $(curl -fsSL https://ipv4.icanhazip.com | tr -d '\n' | base64)
YML

LocalTunnel » Install

cat <<'YML'| \
kubectl apply -n localtunnel -f -
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: localtunnel
  namespace: localtunnel
  labels:
    app: localtunnel
    app.kubernetes.io/name: localtunnel
    app.kubernetes.io/managed-by: kubectl
    app.kubernetes.io/version: 2025.10.24
    app.kubernetes.io/instance: localtunnel
  annotations:
    kubernetes.io/change-cause: 'CKI-1| Initial Deployment'
spec:
  replicas: 1
  selector:
    matchLabels:
      app: localtunnel
  template:
    metadata:
      labels:
        app: localtunnel
    spec:
      securityContext:
        runAsUser: 0
        fsGroup: 0
      containers:
        - name: localtunnel
          image: node:25.0-alpine
          imagePullPolicy: IfNotPresent
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 100m
              memory: 128Mi
          envFrom:
            - secretRef:
                name: localtunnel
            - configMapRef:
                name: localtunnel
          command:
            - /bin/sh
            - -c
            - |
              echo "Installing localtunnel" && \
              npm config set progress false  && \
              npm config set loglevel silent && \
              npm install -g   localtunnel   && \
              echo "Waiting for ${LOCAL_HOST} to be ready..." && \
              until nc -z "${LOCAL_HOST}" "${PORT}"; do echo "waiting..."; sleep 3; done; echo "Starting localtunnel..." && \
              echo   "lt --host  ${LT_HOST}  --local-host  ${LOCAL_HOST}  --port  ${PORT} --subdomain   ${LT_SUBDOMAIN}  ${LT_PRINT_REQUESTS}" && \
              echo   ;lt --host "${LT_HOST}" --local-host "${LOCAL_HOST}" --port "${PORT}" --subdomain "${LT_SUBDOMAIN}" "${LT_PRINT_REQUESTS}"
          stdin: true
          tty: true
      restartPolicy: Always
YML

LocalTunnel » Reconf

cat << YML| \
kubectl -n localtunnel patch configmap \
 localtunnel --type merge --patch-file=/dev/stdin
---
data:
  LT_SUBDOMAIN: pihole-shahed
  LOCAL_HOST:   192.168.49.110
YML
cat << YML| \
kubectl -n localtunnel patch secret \
 localtunnel --type merge --patch-file=/dev/stdin
---
data:
  LT_PASSWORD: $(curl -fsSL https://ipv4.icanhazip.com | tr -d '\n' | base64)

YML
cat <<'YML' | \
kubectl -n localtunnel patch deploy/localtunnel --patch-file=/dev/stdin
---
spec:
  replicas: 0
YML
cat <<'YML' | \
kubectl -n localtunnel patch deploy/localtunnel --patch-file=/dev/stdin
---
spec:
  replicas: 1
YML

LocalTunnel » Debug

LOCALTUNNEL_POD="$(kubectl -n localtunnel get pods -l app=localtunnel -o jsonpath='{.items[0].metadata.name}')"
kubectl -n localtunnel exec -it "${LOCALTUNNEL_POD}" -- printenv|grep LT
kubectl -n localtunnel exec -it "${LOCALTUNNEL_POD}" -- ash
kubectl -n localtunnel logs -f  "${LOCALTUNNEL_POD}"
kubectl -n localtunnel get secret localtunnel -o json|jq -r .data.LT_PASSWORD|base64 -d && echo

setsid open https://pihole-shahed.loca.lt/admin/ >/dev/null 2>&1 &
setsid open         http://pihole.k8s.ops/admin/ >/dev/null 2>&1 &
setsid open         http://192.168.49.110/admin/ >/dev/null 2>&1 &

<<'DIY'
kubectl -n localtunnel get    deploy  localtunnel
kubectl -n localtunnel delete deploy  localtunnel
kubectl                delete ns      localtunnel
DIY