# istio_serviceentry-workloadentry.yaml
# Set up a Service associated with our proxy, which will run as 1.1.1.1 IP
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
  name: proxy-service-instance
spec:
  hosts:
    - example.com
  ports:
    - number: 80
      name: http
      protocol: HTTP
    - number: 7070
      name: tcp
      protocol: TCP
    - number: 443
      name: https
      protocol: HTTPS
    - number: 9090
      name: auto
      protocol: ""
  resolution: STATIC
  location: MESH_INTERNAL
  endpoints:
    - address: 1.1.1.1
      labels:
        security.istio.io/tlsMode: istio
---
# Set up .Services number of services. Each will have 4 ports (one for each protocol)
{{- range $i := until .Services }}
apiVersion: networking.istio.io/v1
kind: ServiceEntry
metadata:
  name: service-{{$i}}
spec:
  hosts:
    - random-{{$i}}.host.example
  ports:
    - number: 80
      name: http
      protocol: HTTP
    - number: 7070
      name: tcp
      protocol: TCP
    - number: 443
      name: https
      protocol: HTTPS
    - number: 9090
      name: auto
  resolution: STATIC
  location: MESH_INTERNAL
  workloadSelector:
    labels:
      app: random-{{$i}}

---
{{- end }}

---
{{- range $j := until .Instances }}
apiVersion: networking.istio.io/v1
kind: WorkloadEntry
metadata:
  name: random-{{$j}}
spec:
  serviceAccount: random
  address: 240.241.{{div $j 255 }}.{{mod $j 255 }}
  labels:
    app: random-{{mod $j $.Services}}
---
{{- end }}