From ac253d76c551d40ac685261e751fb5c7f7cdba0d Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Sat, 12 Apr 2025 08:18:52 +1000 Subject: [PATCH] Archive mysql --- .gitignore | 60 ++++++++++++++++++++++++++++- db/mysql.yaml | 102 ------------------------------------------------- k3s.sh | 6 +++ restore-k8s.sh | 14 +++---- 4 files changed, 72 insertions(+), 110 deletions(-) delete mode 100644 db/mysql.yaml create mode 100644 k3s.sh diff --git a/.gitignore b/.gitignore index 6ec2175..7ea0236 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,61 @@ temp.yaml **/.terraform -*.tar.gz \ No newline at end of file +*.tar.gz + + +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used for local development +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# Ignore lock files +.terraform.lock.hcl + +# Ignore generated scripts +scripts/*.sh + +# Ignore temporary files +*.tmp +*.bak +*.swp + +# Ignore log files +*.log + +# Ignore local environment files +.env +.envrc + +# Ignore any local kubeconfig files +kubeconfig* + +# Ignore any generated YAML files +*.yaml +*.yml + +# Ignore any SSH keys or sensitive files +*.pem +*.key +*.pub + +**/tmp/ \ No newline at end of file diff --git a/db/mysql.yaml b/db/mysql.yaml deleted file mode 100644 index 71fbbeb..0000000 --- a/db/mysql.yaml +++ /dev/null @@ -1,102 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: mysql -spec: - replicas: 1 - selector: - matchLabels: - app: mysql - template: - metadata: - labels: - app: mysql - spec: - nodeSelector: - kubernetes.io/hostname: server-3 - tolerations: - - key: "node" - operator: "Equal" - value: "special" - effect: "NoSchedule" - - key: node-role.kubernetes.io/master - operator: Equal - value: "" - effect: NoSchedule - - key: node-role.kubernetes.io/control-plane - operator: Equal - value: "" - effect: NoSchedule - containers: - - name: mysql - image: mirror.gcr.io/mysql:8.2 - ports: - - containerPort: 3306 - env: - - name: TZ - value: "Australia/Melbourne" - - name: MYSQL_DATABASE - value: home - - name: MYSQL_USER - value: junv - - name: MYSQL_PASSWORD - valueFrom: - secretKeyRef: - name: mysql-password-junv - key: password - - name: MYSQL_ROOT_PASSWORD - valueFrom: - secretKeyRef: - name: mysql-root-password - key: password - volumeMounts: - - name: data - mountPath: "/var/lib/mysql" - resources: - limits: - cpu: "1" - memory: "1Gi" - requests: - cpu: "400m" - memory: "256Mi" - securityContext: - privileged: false - runAsGroup: 1000 - # fsGroup: 1000 - runAsUser: 1000 - volumes: - - name: data - persistentVolumeClaim: - claimName: mysql-local-pvc - ---- -apiVersion: v1 -kind: Service -metadata: - name: mysql-adguard - namespace: db - annotations: - metallb.universe.tf/loadBalancerIPs: 192.168.1.201 -spec: - selector: - app: mysql - ports: - - protocol: TCP - port: 3306 - targetPort: 3306 - type: LoadBalancer - externalIPs: - - 192.168.1.201 - ---- -apiVersion: v1 -kind: Service -metadata: - name: mysql -spec: - selector: - app: mysql - ports: - - protocol: TCP - port: 3306 - targetPort: 3306 diff --git a/k3s.sh b/k3s.sh new file mode 100644 index 0000000..c4cdd8d --- /dev/null +++ b/k3s.sh @@ -0,0 +1,6 @@ +# NFS client storageclass provisioner + +helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/ + +helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \ + --set nfs.server=192.168.1.4 --set nfs.path=/k8s \ No newline at end of file diff --git a/restore-k8s.sh b/restore-k8s.sh index 3bab8f6..d5c1068 100755 --- a/restore-k8s.sh +++ b/restore-k8s.sh @@ -14,13 +14,13 @@ tar -xzf "$BACKUP_FILE" BACKUP_DIR=$(tar -tzf "$BACKUP_FILE" | head -1 | cut -f1 -d"/") # Install k3s if not present -if ! command -v k3s >/dev/null 2>&1; then - echo "Installing k3s..." - curl -sfL https://get.k3s.io | sh - - mkdir -p ~/.kube - sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config - sudo chown $(id -u):$(id -g) ~/.kube/config -fi +# if ! command -v k3s >/dev/null 2>&1; then +# echo "Installing k3s..." +# curl -sfL https://get.k3s.io | sh - +# mkdir -p ~/.kube +# sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config +# sudo chown $(id -u):$(id -g) ~/.kube/config +# fi # Wait for k3s to be ready echo "Waiting for k3s to be ready..."