After deploying the controller application successfully we need to expose it with a service. An easy way to do that would be with a
kubectl expose deployment k8s-admission-demo --type=ClusterIP --port=443 --target-port=9000 --dry-run=client -o yaml
That will create the following object:
apiVersion: v1
kind: Service
metadata:
creationTimestamp: null
labels:
app: k8s-admission-demo
name: k8s-admission-demo
spec:
ports:
- port: 443
protocol: TCP
targetPort: 9000
selector:
app: k8s-admission-demo
type: ClusterIP
status:
loadBalancer: {}
We choose ClusterIP because we do not need to expose this application outside the cluster. So ClusterIP is the right choice for the service.
You can test if the service is working by running an ephemeral pod:
# kubectl run testsrvc -it --restart=Never --image alpine/curl -- sh
/ # curl -k https://k8s-admission-demo.default.svc/validate
empty body
/ # exit
That proves that curl request was sent to our application. -k here is to avoid SSL invalid errors.