---
apiVersion: v1
kind: Namespace
metadata:
  labels:
    app: kubescape
  name: ks-scanner
---
# ------------------- Kubescape Service Account ------------------- #
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: kubescape
  name: kubescape-discovery
  namespace: ks-scanner
---
# ------------------- Kubescape Cluster Role & Cluster Role Binding ------------------- #
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: kubescape-discovery-clusterroles
  # "namespace" omitted since ClusterRoles are not namespaced
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["get", "list", "describe"]

---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: kubescape-discovery-role-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kubescape-discovery-clusterroles
subjects:
- kind: ServiceAccount
  name: kubescape-discovery
  namespace: ks-scanner
---
apiVersion: v1
kind: Service
metadata:
  name: kubescape
  namespace: ks-scanner
  labels:
    app: kubescape
spec:
  type: NodePort
  ports:
    - port: 8080
      name: http
      targetPort: 8080
      protocol: TCP
  selector:
    app: kubescape
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubescape
  namespace: ks-scanner
  labels:
    app: kubescape
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubescape
  template:
    metadata:
      labels:
        app: kubescape
    spec:
      serviceAccountName: kubescape-discovery
      containers:
      - name: kubescape
        livenessProbe:
          httpGet:
            path: /livez
            port: 8080
          initialDelaySeconds: 3
          periodSeconds: 3
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8080
          initialDelaySeconds: 3
          periodSeconds: 3
        image: quay.io/armosec/kubescape:latest
        imagePullPolicy: Always
        env:
        - name: KS_DEFAULT_CONFIGMAP_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: "KS_SKIP_UPDATE_CHECK" # do not check latest version
          value: "true"
        - name: KS_ENABLE_HOST_SCANNER # enable host scanner -> https://hub.armosec.io/docs/host-sensor
          value: "true"              
        - name: KS_DOWNLOAD_ARTIFACTS  # When set to true the artifacts will be downloaded every scan execution
          value: "true" 
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
        command:
        - ksserver
        resources:
          requests:
            cpu: 10m
            memory: 100Mi
          limits:
            cpu: 500m
            memory: 500Mi
