apiVersion: v1
kind: ServiceAccount
metadata:
  name: tidb-image-api
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: tidb-image-api-clusterrole
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "patch", "update"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tidb-image-api-clusterrolebinding
subjects:
  - kind: ServiceAccount
    name: tidb-image-api
    namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: tidb-image-api-clusterrole
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tidb-image-api
  labels:
    app: tidb-image-api
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tidb-image-api
  template:
    metadata:
      labels:
        app: tidb-image-api
    spec:
      serviceAccountName: tidb-image-api
      containers:
        - name: api
          image: docker.io/ysy593/tidb-image-api:v5
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
              name: http
          readinessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
            initialDelaySeconds: 10
            periodSeconds: 15
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 512Mi
---
apiVersion: v1
kind: Service
metadata:
  name: tidb-image-api
  annotations:
    service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
    service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
spec:
  type: LoadBalancer
  selector:
    app: tidb-image-api
  ports:
    - name: http
      port: 80
      targetPort: 8080
      protocol: TCP
  loadBalancerSourceRanges:
    - "44.231.162.131/32"
    - "100.20.198.224/32"
    - "54.188.27.23/32"
    - "34.105.93.217/32"
#    - "0.0.0.0/0"