[k8s 구축] 11. nextcloud 구축

nextcloud는 온프레미스 환경에서 웹 기반 저장소 서비스를 제공하는 도구이다.
필자는 프로젝트를 하면서 공용 저장소가 필요하게 되어 서비스를 구축하게 되었는데 꽤 쓸만하다.

nextcloud를 구축할 땐 두 가지를 주의하면 된다.
메타데이터 저장을 위한 별도의 DB가 필요하다는 것과, nextcloud가 저장소 내부에서 권한을 관리한다는 점이다.

전자의 경우 MySQL을 하나 만들어 연동하면 그만이나 후자의 경우 저장소의 권한을 적절히 설정해주어야 한다.
필자의 경우 nfs 프로비저닝을 통해 네트워크 pv를 구성하고 있기에 더더욱 문제가 되었다.
보안 문제로 루트 권한을 허용하지 않았기 때문이다.
그러나 nextcloud를 사용하는 이상 어쩔 수 없이 nfs 서버 사용자에게 루트 권한을 부여할 수밖에 없다.
필자가 nfs 클라이언트 네트워크를 신뢰하고 있기 때문에 가능한 일이다.

0. nfs 설정

필자의 경우 nfs 프로비저닝을 하고 있기에 nfs 서버에서 /etc/exports 파일을 수정하였다.
핵심은 no_root_squash를 추가해 nfs 클라이언트에게 root 권한을 부여하는 것이다.

# /etc/exports
/nfs/export/path *(rw,sync,no_subtree_check,no_root_squash)

수정한 이후에는 nfs 설정을 갱신하거나 서버를 재시작해야 한다.

$ sudo exportfs -ra

1. nextcloud 구축

이제 별거 없다.
매니페스트 파일을 다음과 같이 만들어 배포하기만 하면 된다.

nextcloud는 웹 서비스이기에 ingress controller를 통해 서비스하기로 하였다.
이를 위해 ClusterIP 방식의 서비스를 구성하고 덤으로 TLS 인증서도 적용하였다.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nextcloud-pvc
  namespace: nextcloud
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: nfs-csi
  resources:
    requests:
      storage: 100Gi

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nextcloud
  namespace: nextcloud
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nextcloud
  template:
    metadata:
      labels:
        app: nextcloud
    spec:
      containers:
        - name: nextcloud
          image: nextcloud
          ports:
            - containerPort: 80
          volumeMounts:
            - mountPath: /var/www/html
              name: nextcloud-storage
      volumes:
        - name: nextcloud-storage
          persistentVolumeClaim:
            claimName: nextcloud-pvc

---

apiVersion: v1
kind: Service
metadata:
  name: nextcloud-service
  namespace: nextcloud
spec:
  selector:
    app: nextcloud
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

---

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nextcloud-ingress
  namespace: nextcloud
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:   
  ingressClassName: nginx
  tls:
    - hosts:
        - aaa.bbb.com
      secretName: wildcard-tls
  rules:    
    - host: aaa.bbb.com
      http: 
        paths:
          - path: /
            pathType: Prefix
            backend:
              service: 
                name: nextcloud-service
                port:
                  number: 80

이제 aaa.bbb.com으로 접속해 admin 계정을 설정하며 로그인하면 된다.
물론 nextcloud용 DB는 이미 준비되어있어야 한다. (이전 글 참고)

당연한 이야기지만 필자는 aaa.bbb.com 도메인 네임이 ingress controller의 외부 IP로 바인딩되어있기 때문에 위 매니페스트 파일처럼 서비스를 구성해 사용할 수 있다.

Series Navigation<< [k8s 구축] 10. MySQL 구축

댓글 남기기