Using Services in Kubernetes

Objective

After completing this lesson, you will be able to use services in Kubernetes

Create a Service for a Deployment

Business Scenario

You have already deployed your application to a Kubernetes cluster using a deployment. Before exposing it to the outside world, you must define a stable internal endpoint for the deployment. This is done by creating a Service.

Live Environment

In this exercise, you will create a Service for the deployment in three steps:

  1. Create a Service manifest and apply it to the cluster.
  2. Verify the created Service with kubectl.
  3. Verify the created Service with Kyma dashboard.

Prerequisites

  • You have successfully created a SAP BTP, Kyma runtime instance in the SAP BTP subaccount.
  • You have the default modules API Gateway and Istio added to your SAP BTP, Kyma runtime instance.
  • You have configured kubectl to work with your SAP BTP, Kyma runtime instance.
  • You have successfully created the hello-kyma deployment in the previous exercise.

Task 1: Create a Service manifest and apply it to the cluster

Steps

  1. Create a Service manifest and apply it to the cluster.

    1. Create a file named hello-kyma-svc.yaml with the following content:

      Code Snippet
      1234567891011
      apiVersion: v1 kind: Service metadata: name: hello-kyma-svc spec: selector: app: 'hello-kyma' # must match the pod's label ports: - protocol: 'TCP' port: 80 # Service port targetPort: 8080 # pod port
    2. Apply the Service manifest to the cluster.

      Code Snippet
      1
      kubectl apply -f hello-kyma-svc.yaml
  2. Verify the created Service with kubectl.

    Use kubectl to list your Services.

    Code Snippet
    1
    kubectl get svc

    Note

    svc is the short form of Service. Most of the Kubernetes resources have a short form. You can use the short form in most of the kubectl commands.
  3. Verify the created Service in Kyma dashboard.

    Open Kyma dashboard and navigate to the Services view.

    Services

    You should see the hello-kyma-svc Service listed. Choose it to see the details.

    Service Resource Graph

    You will expose the Service to the outside world in the next exercise.

Result

You have successfully created a Service for the deployment.

Log in to track your progress & complete quizzes