Linux, 工作, 生活, 家人

Cloud

Install phpIPAM on Kubernetes

This article is talking about how to install phpIPAM on Kubernetes, some thought might be used on other package .

It used the helm to install the phpipam(helm version) on K8s.

Install phpipam command

kubectl create namespace phpipam
kubectl create secret generic mysql-password --from-literal='password=<mysql password>' -n phpipam

helm repo add phpipam https://nullconfig.github.io/phpipam/stable
helm repo update
helm install --namespace phpipam --create-namespace phpipam phpipam/phpipam

Setup Storage

if you have not setup the phpipam storge or default storage, it will show warning message on describe pods like this

$ kubectl describe pods phpipam-5f5f456d75-69hk7 -n phpipam

Events:
  Type     Reason            Age                 From               Message
  ----     ------            ----                ----               -------
  Warning  FailedScheduling  17s (x4 over 3m8s)  default-scheduler  0/3 nodes are available: pod has unbound immediate PersistentVolume
Claims. preemption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling..

That’s means there is no PersistentVolume (pv) and PersistentVolume Claims (pvc) on your system, it needs to create one.

Here is pv.yaml contain.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: phpipam
  namespace: phpipam
spec:
  capacity:
    storage: 100Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /data
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - k8s-node1

k8s-node1 is your storage node, function local: only can save storage on one node, if you setup it on master node, it will see this error message

Events:
  Type     Reason            Age    From               Message
  ----     ------            ----   ----               -------
  Warning  FailedScheduling  2m11s  default-scheduler  0/3 nodes are available: persistentvolumeclaim "phpipam" not found. preemption:
0/3 nodes are available: 3 Preemption is not helpful for scheduling..
  Warning  FailedScheduling  34s    default-scheduler  0/3 nodes are available: pod has unbound immediate PersistentVolumeClaims. preem
ption: 0/3 nodes are available: 3 Preemption is not helpful for scheduling..
  Warning  FailedScheduling  31s    default-scheduler  0/3 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.i
o/control-plane: }. preemption: 0/3 nodes are available: 1 Preemption is not helpful for scheduling, 2 No preemption victims found for
incoming pod..

It needs to prepare pvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: phpipam
  namespace: phpipam
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-storage
  resources:
    requests:
      storage: 100Gi

Then, it can run apply them

kubectl apply -f pv.yaml 
kubectl apply -f pvc.yaml 
kubectl get pv -A
kubectl get pvc -A

Change the phpIPAM type from ClusterIP to LoadBalancer

After finish setup the system, it needs to change the phpipam-web’s CludsterIIP to LoadBalancer to get external IP

$ kubectl get svc -A
phpipam          phpipam-db                  ClusterIP      10.101.2.59      <none>            3306/TCP                     3h22m
phpipam          phpipam-web                 ClusterIP      10.108.147.73    <none>            80/TCP                       3h22m
$ kubectl patch svc phpipam-web -n phpipam -p '{"spec": {"ports": [{"port": 443,"targetPort": 443,"name": "https"},
{"port": 80,"targetPort": 80,"name": "http"}],"type": "LoadBalancer"}}'
$ kubectl get svc -A
phpipam          phpipam-db                  ClusterIP      10.101.2.59      <none>            3306/TCP                     4h18m
phpipam          phpipam-web                 LoadBalancer   10.108.147.73    192.168.110.202   443:32226/TCP,80:30911/TCP   4h18m

Now, it can use browser to access the phpIPAM web via IP 192.168.110.202

ref.
kubectl – How to edit service spec type to LoadBalancer via command line?

發佈留言