apiVersion: v1
kind: Service
metadata:
  name: crawlab
  namespace: crawlab
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: crawlab-master

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: crawlab-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
    kubernetes.io/tls-acme: "true"
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    nginx.ingress.kubernetes.io/auth-url: "https://pass.junv.cc/oauth2/auth"
    nginx.ingress.kubernetes.io/auth-signin: "https://pass.junv.cc/oauth2/start?rd=https://$host$escaped_request_uri"
spec:
  tls:
  - hosts:
    - crawlab.junv.cc
    secretName: crawlab-tls
  rules:
  - host: crawlab.junv.cc
    http:
      paths:
      - backend:
          service:
            name: crawlab
            port:
              number: 80
        path: /
        pathType: Prefix

---
# master
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: crawlab-master
  namespace: crawlab
spec:
  serviceName: crawlab-master
  selector:
    matchLabels:
      app: crawlab-master
  template:
    metadata:
      labels:
        app: crawlab-master
    spec:
      containers:
      - image: tikazyq/crawlab:latest
        imagePullPolicy: IfNotPresent
        name: crawlab
        env:
        - name: CRAWLAB_SERVER_MASTER
          value: "Y"
        - name: CRAWLAB_MONGO_HOST
          value: "mongodb.db.svc.cluster.local"
        - name: CRAWLAB_REDIS_ADDRESS
          value: "192.168.1.2"
        - name: CRAWLAB_REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: redis-password
              key: password
        - name: CRAWLAB_SETTING_ALLOWREGISTER
          value: "Y"
        - name: CRAWLAB_SERVER_LANG_NODE
          value: "N"
        - name: CRAWLAB_SERVER_LANG_JAVA
          value: "N"
        - name: CRAWLAB_SERVER_LANG_DOTNET
          value: "N"
        - name: CRAWLAB_SERVER_REGISTER_TYPE
          value: "hostname"
        - name: CRAWLAB_MONGO_DB
          value: "crawlab"
        - name: CRAWLAB_MONGO_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-password
              key: username
        - name: CRAWLAB_MONGO_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-password
              key: password
        ports:
        - containerPort: 8080
          name: crawlab

---
# worker

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: crawlab-worker
  namespace: crawlab
spec:
  serviceName: crawlab-worker
  replicas: 2
  selector:
    matchLabels:
      app: crawlab-worker
  template:
    metadata:
      labels:
        app: crawlab-worker
    spec:
      containers:
      - image: tikazyq/crawlab:latest
        imagePullPolicy: IfNotPresent
        name: crawlab
        env:
        - name: CRAWLAB_SERVER_MASTER
          value: "N"
        - name: CRAWLAB_MONGO_HOST
          value: "mongodb.db.svc.cluster.local"
        - name: CRAWLAB_MONGO_DB
          value: "crawlab"
        - name: CRAWLAB_MONGO_USERNAME
          valueFrom:
            secretKeyRef:
              name: mongodb-password
              key: username
        - name: CRAWLAB_MONGO_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mongodb-password
              key: password
        - name: CRAWLAB_REDIS_ADDRESS
          value: "redis-master.db.svc.cluster.local"
        - name: CRAWLAB_REDIS_PASSWORD
          valueFrom:
            secretKeyRef:
              name: redis-password
              key: password
        - name: CRAWLAB_SERVER_LANG_NODE
          value: "Y"
        - name: CRAWLAB_SERVER_LANG_JAVA
          value: "Y"
        - name: CRAWLAB_SERVER_LANG_DOTNET
          value: "Y"
        - name: CRAWLAB_SERVER_REGISTER_TYPE
          value: "hostname"
