Skip to content

Instantly share code, notes, and snippets.

@nhahv
Last active September 16, 2021 10:01
Show Gist options
  • Save nhahv/bd318dd29f4186f1b5fd748713d445b2 to your computer and use it in GitHub Desktop.
Save nhahv/bd318dd29f4186f1b5fd748713d445b2 to your computer and use it in GitHub Desktop.
[Kubenetes] Kubenetes Setup #k8s #setup

Expoise LoadBalancer Service

kubectl --namespace default get service


#NAME                                TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
#kubernetes                          ClusterIP      10.96.0.1       <none>        443/TCP                      19h
#nginx-ingress-xxx                   LoadBalancer   10.102.23.116   <pending>     80:30199/TCP,443:30207/TCP   3m27s
#nginx-ingress-xxx-default-backend   ClusterIP      10.100.69.157   <none>        80/TCP                       3m27s

kubectl --namespace default edit service nginx-ingress-controller-1631689791
spec:
  type: LoadBalancer
+  externalIPs:
+  - 192.168.68.144
  allocateLoadBalancerNodePorts: true
  clusterIP: 10.102.23.116
k -n default get service nginx-ingress-controller-1631689791
#NAME                TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                      AGE
#nginx-ingress-xxx   LoadBalancer   10.102.23.116   192.168.68.144   80:30199/TCP,443:30207/TCP   10m
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress-default
  annotations:
    # use the shared ingress-nginx
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              serviceName: tickvn-api-auth
              servicePort: 80
mkdir -p /root/data
chmod -R 777 /root/data/

Ghost MariaDB

kind: PersistentVolume
apiVersion: v1
metadata:
  name: data-ghost-mariadb-pv-0
  labels:
    type: hostpath
spec:
  storageClassName: "hostpath"
  volumeMode: Filesystem
  persistentVolumeReclaimPolicy: Retain
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /root/data/data-ghost-mariadb-pv-0
  claimRef:
    kind: PersistentVolumeClaim
    namespace: ghost
    name: data-ghost-mariadb-0

Ghost Data

kind: PersistentVolume
apiVersion: v1
metadata:
  name: data-ghost-pv-0
  labels:
    type: hostpath
spec:
  storageClassName: "hostpath"
  volumeMode: Filesystem
  persistentVolumeReclaimPolicy: Recycle # 
  capacity:
    storage: 10Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /root/data/data-ghost-pv-0
  claimRef:
    kind: PersistentVolumeClaim
    namespace: ghost
    name: ghost
chown -R 1001:1001 /root/data/data-ghost-pv-0

📕 Note

persistentVolumeReclaimPolicy: Retain | Delete | Recycle (deprecated)

  • Retain: When PVC is deleted, the PV still exists 🡪 Manual reclamation of the resource (Adminstrator: delete PV and associated data, then )
  • Delete: Remove both PV /aws the associated storage
  • Recyle: Remove all the content (rm -rf /the-volume/*) then make it avalable again
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment