Before you create a connection policy, the service that is referenced in the policy must
be registered in IBM® Hybrid Cloud Mesh. Run the kubectl expose
deployment command to create the Kubernetes service object. When the Kubernetes service is
successfully created, Mesh automatically discovers and registers
the service.
About this task
The kubectl expose deployment command creates a service object in
Kubernetes that allows traffic to reach the application that runs in the deployment. For more
information and examples of how to use the kubectl expose command, see Expose a resource as a Kubernetes service.
Important: Using the kubectl expose command to expose resources other
than deployments is not supported.
If the service is not already registered in Mesh, complete
the following steps.
Procedure
- Run commands that are similar to the following examples to create the Kubernetes service
object.
In a Kubernetes
environment:
kubectl expose deployment <deployment-name> --port=<port-to-expose> --target-port=<port-exposed-by-app-pod>
In an OpenShift® Container Platform environment:
oc expose deployment <deployment-name> --port=<port-to-expose> --target-port=<port-exposed-by-app-pod>
- <deployment-name> is the group of pods that are managed by the
deployment.
- <port-to-expose> is the port that applications can use to connect to the
Kubernetes service.
- <port-exposed-by-app-pod> is the port, inside the deployment, that the
Kubernetes service routes traffic to.
In the following example, the deployment
my-deployment is exposed on port 80
of the Kubernetes service. Traffic is routed to port 30080 inside the
deployment.
kubectl expose deployment my-deployment --port=80 --target-port=30080
When the Kubernetes service is successfully created, Mesh
automatically discovers and registers the service.
- Check that the Kubernetes service is created by running commands like these. For OpenShift Container Platform environments, replace
kubectl with oc.
To see that the service was created successfully, list all the
services:
kubectl get services
Get details about
the
service:
kubectl describe services <service-name>
- Check that the service is registered in Mesh:
- Get the application
name:
palmctl get applications
- Get the Mesh
service:
palmctl get services --application-name <application-name>
Wait until the service is discovered and registered in
Mesh
before you create the connection policy.