Project:K8s commands
From MaRDI portal
Accessing internally deployed services
During development it is often useful to deploy services that are only internally accessible within the cluster.
The types of services that we can attach to any kubernetes resource are NodePort, ClusterIP and LoadBalancer.
LoadBalancerwould be the choice if we want to assign an external IP to the resource in order to make the service accessible from outside the cluster.- If instead we don't want to make the service externally available we can assign to it a service of type
ClusterIPand then use port forwarding throughkubectlto access it.
Steps
- 1) Create a service of type
ClusterIPdefining the correspondingyamlfile or changing the configuration parameters of the resource, if for instance, it is defined through a helm chart that uses already some default service.
- 2) Check that the service has been created in the corresponding namespace. For instance, if we want to check the service in the namespace
staging, we can run:
kubectl get svc -n staging
- which will return the list of services, among which we can find our service of interest, which in this case could be the wikibase deployment:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE staging-wikibase ClusterIP 10.102.203.7 <none> 80/TCP 14d
- 3) Knowing this service name (
staging-wikibase) and the port where it is running (80), we can port forward it to our local machine using:
kubectl port-forward -n staging svc/staging-wikibase 8080:80
- 4) Access the service from
http://localhost:8080.