Project:K8s commands

From MaRDI portal
Revision as of 09:59, 19 March 2025 by EloiFerrer (talk | contribs) (Created page with "== 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 <code>NodePort</code>, <code>ClusterIP</code> and <code>LoadBalancer</code>. * <code>LoadBalancer</code> would be the choice if we want to assign an external IP to the resource in order to make the service accessible from outside the c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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.

  • LoadBalancer would 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 ClusterIP and then use port forwarding through kubectl to access it.

Steps

  • 1) Create a service of type ClusterIP defining the corresponding yaml file 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