catalog
catalog copied to clipboard
Re-design ServiceExpose trait
The idea is Expose should answer below questions:
- which target port I want to expose?
- expose to what service port?
- what's the type of this expose?
- what's the protocol?
It should be a list, with Kind of Expose. So I'd suggest re-design ServiceExpose as below.
Example 1:
apiVersion: core.oam.dev/v1alpha2
kind: Expose
spec:
servicePorts:
- port: 80
targetPort: 80
- port: 8001
targetPort: 9376
This will generate one k8s Service:
apiVersion: v1
kind: Service
metadata:
name: <component-name>-clusterip
spec:
clusterIP: 10.96.193.247 # auto gen
ports:
- name: tcp-80 # auto gen
port: 80
protocol: TCP # default
targetPort: 80
- name: tcp-8080 # auto-gen
port: 8080
protocol: TCP # default
targetPort: 80
selector:
component: <component-name>
type: ClusterIP
Example 2:
apiVersion: core.oam.dev/v1alpha2
kind: Expose
spec:
servicePorts:
- port: 80
targetPort: 80
type: NodePort
- port: 8001
targetPort: 9376
clusterIP: 10.0.171.239
type: LoadBalancer
protocol: HTTP
This will generate two k8s Services:
apiVersion: v1
kind: Service
metadata:
name: <component-name>-nodeport
spec:
type: NodePort
ports:
- name: tcp-80 # auto gen
port: 80
protocol: TCP # default
targetPort: 80
selector:
component: <component-name> # this is auto label for workload
apiVersion: v1
kind: Service
metadata:
name: <component-name>-loadbalancer
spec:
type: LoadBalancer
clusterIP: 10.0.171.239
ports:
- name: http-8001 # auto gen
port: 8001
protocol: HTTP
targetPort: 9376
selector:
component: <component-name> # this is auto label for workload
For auto labels of workload, ref: https://github.com/crossplane/oam-kubernetes-runtime/issues/174
/cc @wonderflow
I would recommend to take a look at the port abstraction in Exposing the service section in this blog: https://medium.com/kapitan-blog/keep-your-ship-together-with-kapitan-d82d441cc3e7