Helm/Yourls: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 346: Line 346:
<syntaxhighlight style='margin:3px 0' lang='yaml'>
<syntaxhighlight style='margin:3px 0' lang='yaml'>
cat <<'YML' | \
cat <<'YML' | \
helm -n=yourls upgrade -i yourls yourls/yourls --version=8.5.8 -f -
helm --history-max=5 -n=yourls \
upgrade -i yourls yourls/yourls --version=8.5.8 -f -
---
---
replicaCount: 1
replicaCount: 1
Line 775: Line 776:
* [https://yourls.org/docs/guide/advanced/passwordless-api Yourls » API » Passwordless]
* [https://yourls.org/docs/guide/advanced/passwordless-api Yourls » API » Passwordless]
* [https://yourls.org/docs/guide/advanced/api Yourls » API]
* [https://yourls.org/docs/guide/advanced/api Yourls » API]
* [[Yourls]]


|valign='top' style='width:33%'|
|valign='top' style='width:33%'|

Latest revision as of 00:57, 27 December 2025

helm repo add yourls https://charts.yourls.org
helm repo update && helm repo list
kubectl config get-contexts

Data

Data

Data » HostPath

ssh -qt shahed@shahed-ab.local.or.tunnel.ip bash
sudo su

cat <<'EXE'| sudo bash
    mkdir -p       /var/minikube/pvc/yourls/data-mariadb-0/
chown -R 1001:1001 /var/minikube/pvc/yourls/
EXE

Data » MariaDB

MariaDB » Create

ssh -qt shahed@shahed-ab.local.or.tunnel.ip bash
echo -n 'Password: ';read -s TOOL_YOURLS;export TOOL_YOURLS;echo
# Password: sadaqah!
cat <<'SQL'| sudo -i -u root mariadb
\! echo " "
SELECT concat(user, '@', host) AS 'user\n+--------------------------+' FROM mysql.user ORDER BY 1 ASC;
\! echo " "
-- SHOW databases;
SELECT schema_name         AS 'database\n+--------------------------+' FROM information_schema.schemata ORDER BY 1 ASC;
SQL
cat << DDL | sudo -i -u root mariadb
CREATE DATABASE IF NOT EXISTS shahed_tool_yourls;
CREATE USER     IF NOT EXISTS shahed_tool_yourls@'%' IDENTIFIED BY '${TOOL_YOURLS}';
GRANT  ALL PRIVILEGES  ON     shahed_tool_yourls.*   TO  shahed_tool_yourls@'%';
FLUSH PRIVILEGES;
DDL

MariaDB » Debug

echo -n 'Password: ';read -s MYSQL_PWD;export MYSQL_PWD;echo
# Password: sadaqah!

sudo -i -u root \
mariadb -D shahed_tool_yourls
mariadb -D shahed_tool_yourls -u shahed_tool_yourls
mariadb -D shahed_tool_yourls -u shahed_tool_yourls -P3306 -h10.20.0.1
mariadb -D shahed_tool_yourls -u shahed_tool_yourls -P3306 -h10.20.13.1
mariadb -D shahed_tool_yourls -u shahed_tool_yourls -P3306 -h192.168.49.1

MariaDB » Backup

ssh -qt shahed@shahed-ab.local.or.tunnel.ip bash
cd ~/Downloads

function quarter() {
 local month this_quarter
 month=$(date +%m)

 case $month in
   01|02|03) this_quarter="$(date +'%Y-01-01')" ;;
   04|05|06) this_quarter="$(date +'%Y-04-01')" ;;
   07|08|09) this_quarter="$(date +'%Y-07-01')" ;;
   10|11|12) this_quarter="$(date +'%Y-10-01')" ;;
 esac

 echo -n "${this_quarter}"
}

echo -n 'password: ';read -s MYSQL_PWD;export MYSQL_PWD; echo
# Password: sadaqah!

BKP_DATETIME="$(date +'%Y-%m-%dT%H%M')";\
mariadb-dump -P3306 -h10.20.13.1 -u shahed_tool_yourls shahed_tool_yourls | gzip > shahed_tool_yourls.${BKP_DATETIME}.sql.gz

MariaDB » Restore

ssh -qt shahed@shahed-ab.local.or.tunnel.ip bash
mc cp s3_minio_shahed_shahed_biz_admin/shahed-bkp/tool/yourls/daily/2025-M12/2025-12-21/shahed_tool_yourls.2025-12-21T2345.sql.gz ${HOME}/Downloads/

echo -n 'password: ';read -s MYSQL_PWD;export MYSQL_PWD; echo
# Password: sadaqah!

mariadb -P3306 -h10.20.13.1 -u shahed_tool_yourls -D shahed_tool_yourls
gunzip -c ${HOME}/Downloads/shahed_tool_yourls.2025-12-21T2345.sql.gz | mariadb -P3306 -h10.20.13.1 -u shahed_tool_yourls -D shahed_tool_yourls

MariaDB » Destroy

ssh -qt shahed@shahed-ab.local.or.tunnel.ip bash
cat <<'DDL'| sudo -i -u root mariadb
\! echo " "
REVOKE ALL PRIVILEGES ON  shahed_tool_yourls.* FROM shahed_tool_yourls@'%';
DROP DATABASE IF  EXISTS  shahed_tool_yourls;
DROP USER     IF  EXISTS  shahed_tool_yourls@'%';
FLUSH PRIVILEGES;
DDL

Config

Config

Config » Context

export KUBECONFIG=${HOME}/.kube/shahed-ab-kubeconfig.yaml
kubectl config get-contexts
kubectl config view
kubectl config view -o=yaml|yq '.contexts[0].name'
kubectl create ns   yourls || true
kubectl get ns|grep yourls

Config » Yourls

Yourls » Certificate

cat <<'YML' | \
kubectl -n yourls apply -f -
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: yourls-cert
  namespace: yourls
spec:
  secretName: yourls-cert
  commonName: go.shahed.biz.ops
  dnsNames:
    - go.shahed.biz.ops
  duration: 8760h
  renewBefore: 720h
  privateKey:
    size: 256
    encoding: PKCS8
    algorithm: ECDSA
    rotationPolicy: Always
  usages:
    - digital signature
    - key encipherment
    - server auth
    - client auth
  subject:
    countries: ["BD"]
    provinces: ["Dhaka"]
    postalCodes: ["1500"]
    localities: ["Munshiganj"]
    organizations: ["Shahed, Inc."]
    organizationalUnits: ["go.shahed.biz.ops"]
    streetAddresses: ["256 Khal East, Passport Office"]
  issuerRef:
    name: shahed-ecc-sub-ca-2025-k8s
    kind: ClusterIssuer
YML

Shahed_ECC_Root_CA_2025 » Firefox » Settings » Certificates » View Certificates » Import

Yourls » Secrect

Secrect » MariaDB

cat << ENV | \
kubectl -n yourls \
 create secret generic yourls-mariadb --from-env-file=/dev/stdin \
 --dry-run=client -o=yaml | kubectl -n yourls apply -f -
mariadb-replication-password=sadaqah!
mariadb-root-password=sadaqah!
mariadb-password=sadaqah!
ENV

Secrect » Yourls

cat << ENV | \
kubectl -n yourls \
 create secret generic yourls --from-env-file=/dev/stdin \
 --dry-run=client -o=yaml | kubectl -n yourls apply -f -
password=sadaqah!
username=admin
ENV

Yourls » Volume



cat <<'YML'| \
kubectl apply -f -

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: yourls-data-mariadb-0
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: hostpath
  hostPath:
    path: /var/hostpath_pv/yourls/data-mariadb-0
    type: DirectoryOrCreate
YML
cat << YML | \
kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  labels:
    app.kubernetes.io/name: yourls
  name: data-mariadb-0
  namespace: yourls
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  storageClassName: hostpath
  volumeName: yourls-data-mariadb-0
YML

Helm » Upgrade

Helm » Upgrade

helm show   values yourls/yourls --version=8.5.6|less
helm show   values yourls/yourls --version=8.5.8|less
kubectl create ns      yourls || true
kubectl get    ns|grep yourls
cat <<'YML' | \
helm --history-max=5 -n=yourls \
 upgrade -i yourls yourls/yourls --version=8.5.8 -f -
---
replicaCount: 1
nameOverride: ops
fullnameOverride: yourls
revisionHistoryLimit: 5

image:
  tag: 1.10.2
  registry: ghcr.io
  repository: yourls/yourls

service:
  type: ClusterIP

yourls:
  scheme: https
  skipInstall: true
  existingSecret: yourls
  domain: go.shahed.biz.ops

ingress:
  enabled: true
  ingressClassName: nginx
  pathType: ImplementationSpecific
  annotations:
    kubernetes.io/tls-acme: "false"
    kubernetes.io/ingress.class: nginx
  hostname: go.shahed.biz.ops
  path: /

resources:
  requests:
    cpu: 50m
    memory: 64Mi
  limits:
    cpu: 100m
    memory: 128Mi

mariadb:
  enabled: false
  architecture: standalone
  image:
    registry: docker.io
    repository: bitnamilegacy/mariadb
    tag: 10.11.9

  auth:
    database: shahed_tool_yourls
    username: shahed_tool_yourls
    existingSecret: yourls-mariadb

  primary:
    persistence:
      size: 1Gi
      enabled: true
      accessModes:
        - ReadWriteOnce
      storageClass: hostpath
      existingClaim: data-mariadb-0

    resources:
      requests:
        cpu: 50m
        memory: 64Mi
      limits:
        cpu: 100m
        memory: 128Mi

externalDatabase:
  port: 3306
  host: 192.168.49.1
  user: shahed_tool_yourls
  database: shahed_tool_yourls
  existingSecret: yourls-mariadb
YML
telnet go.shahed.biz.ops 80
setsid open http://go.shahed.biz.ops/admin/ >/dev/null 2>&1 &

Helm » Patch

Helm » Patch

cat <<'YML' | \
kubectl -n yourls patch ingress/yourls --patch-file=/dev/stdin
---
metadata:
  annotations:
    cert-manager.io/cluster-issuer: shahed-ecc-sub-ca-2025-k8s
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
  tls:
    - hosts:
        - go.shahed.biz.ops
      secretName: yourls-cert
YML
cat <<'YML' | \
kubectl -n yourls patch ingress/yourls --patch-file=/dev/stdin
---
metadata:
  annotations:
    cert-manager.io/cluster-issuer: null
    nginx.ingress.kubernetes.io/ssl-redirect: null
spec:
  tls: null



YML
setsid open  http://go.shahed.biz.ops/admin/ >/dev/null 2>&1 &
setsid open https://go.shahed.biz.ops/admin/ >/dev/null 2>&1 &

Helm » Scale

Yourls » Stop

Yourls » Start

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

Helm » Debug

Helm » Debug

kubectl -n yourls exec -it svc/yourls -c yourls -- cat /etc/resolv.conf
kubectl -n yourls exec -it svc/yourls -c yourls -- cat /etc/hosts
kubectl -n yourls exec -it svc/yourls -c yourls -- bash
kubectl -n yourls logs -f  svc/yourls -c yourls
kubectl -n yourls logs -f  svc/yourls
kubectl -n yourls exec -it svc/yourls -c yourls -- bash
:'
export MYSQL_PWD=$(cat /opt/bitnami/mariadb/secrets/mariadb-password)
mariadb -D shahed_tool_yourls -u shahed_tool_yourls
show databases;
show tables;
'
kubectl -n yourls exec -it svc/yourls -c yourls -- php -r '$name = "Yourls"; echo "Hello, {$name}\n";'
kubectl -n yourls exec -it svc/yourls -c yourls -- php -r '$time =  time() ; echo "Time : {$time}\n";'
kubectl -n yourls exec -it svc/yourls -c yourls -- php -a
:'
php > echo time();
1766766506
php > 
'
kubectl -n yourls exec -it svc/yourls -c yourls -- php -r '$timestamp = time();$signature = md5( $timestamp . "1002a612b4" ); echo "Signature: {$signature}\n";'
kubectl -n yourls exec -it svc/yourls -c yourls -- php -r '$signature = md5( time() . "1002a612b4" ); echo "Signature: {$signature}\n";'
echo; \
cat <<'PHP' | kubectl -n yourls exec -i svc/yourls -c yourls -- php /dev/stdin | xargs curl -s | jq -r .shorturl
<?php
$timestamp = time();
$signature = md5( $timestamp . '1002a612b4' );
echo "https://go.shahed.biz.ops/yourls-api.php?signature={$signature}&timestamp={$timestamp}&action=shorturl&format=json&url=https://google.com";
PHP
echo; \
cat <<'PHP' | kubectl -n yourls exec -i svc/yourls -c yourls -- php /dev/stdin | xargs curl -s | jq -r .shorturl
<?php
$timestamp = time();
$signature = hash( 'sha256' , $timestamp . '1002a612b4' );
echo "https://go.shahed.biz.ops/yourls-api.php?signature={$signature}&timestamp={$timestamp}&hash=sha256&action=shorturl&format=json&url=https://google.com";
PHP

Helm » Rollout

Yourls » Rollout

kubectl -n yourls annotate        deploy/yourls --overwrite \
 kubernetes.io/change-cause="CKI-1| Initial Deployment"
kubectl -n yourls rollout history deploy/yourls
kubectl -n yourls rollout pause   deploy/yourls

Yourls » Rollout

Yourls » Revert

cat <<'YML' | \
kubectl -n yourls patch deploy/yourls --patch-file=/dev/stdin
---
spec:
  template:
    spec:
      containers:
        - name: yourls
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 200m
              memory: 256Mi
YML
cat <<'YML' | \
kubectl -n yourls patch deploy/yourls --patch-file=/dev/stdin
---
spec:
  template:
    spec:
      containers:
        - name: yourls
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 100m
              memory: 128Mi
YML
kubectl -n yourls annotate        deploy/yourls --overwrite \
 kubernetes.io/change-cause="CKI-2| Resources Updated"
kubectl -n yourls rollout resume  deploy/yourls
kubectl -n yourls rollout history deploy/yourls
kubectl -n yourls rollout undo    deploy/yourls --to-revision=1
kubectl -n yourls rollout history deploy/yourls
kubectl -n yourls annotate        deploy/yourls --overwrite \
 kubernetes.io/change-cause="CKI-3| Revert Back to CKI-1"
kubectl -n yourls get deploy yourls -o yaml \
 | yq -P '.spec.template.spec.containers[]|select(.name == "yourls")|.resources'
kubectl -n yourls get deploy yourls \
  -o jsonpath='{.spec.template.spec.containers[?(@.name=="yourls")].resources}' | yq -P

Helm » Uninstall

Helm » Uninstall

kubectl delete ns           yourls
helm    -n yourls status    yourls
helm    -n yourls get all   yourls
helm    -n yourls uninstall yourls

kubectl -n yourls  delete pvc --all
kubectl delete pv yourls-data-mariadb-0

Playground

Playground

helm -n yourls install    yourls yourls/yourls --version=8.5.6
helm -n yourls upgrade -i yourls yourls/yourls --version=8.5.8
helm show   values yourls/yourls --version=8.5.8|less
kubectl -n yourls get  secret  yourls-mariadb -o json|jq -r '.data."mariadb-replication-password"'|base64 -d && echo
kubectl -n yourls get  secret  yourls-mariadb -o json|jq -r '.data."mariadb-root-password"'       |base64 -d && echo
kubectl -n yourls get  secret  yourls-mariadb -o json|jq -r '.data."mariadb-password"'            |base64 -d && echo

kubectl -n yourls get  secret  yourls -o json|jq -r '.data.username'|base64 -d && echo
kubectl -n yourls get  secret  yourls -o json|jq -r '.data.password'|base64 -d && echo

kubectl -n yourls exec -it svc/yourls -c yourls -- bash
kubectl -n yourls logs -f  svc/yourls -c yourls
kubectl -n yourls logs -f  svc/yourls
kubectl config --kubeconfig=${HOME}/.kube/aws-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/dev-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/gcp-kubeconfig.yaml view --flatten
kubectl config --kubeconfig=${HOME}/.kube/config view --flatten
kubectl -n yourls delete all --all
kubectl -n yourls delete ing --all
kubectl -n yourls delete sts --all
kubectl    delete pv     yourls-data-mariadb-0
kubectl -n yourls delete svc --all
kubectl -n yourls delete pvc --all
kubectl -n yourls rollout history deploy yourls
kubectl -n yourls rollout restart deploy yourls
kubectl -n yourls rollout status  deploy yourls
kubectl -n yourls exec -it svc/yourls -c yourls -- ash
kubectl -n yourls logs -f  svc/yourls -c yourls
kubectl -n yourls logs -f  svc/yourls

References

References