Using Services in Kubernetes

Objectives
After completing this lesson, you will be able to:

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.

Exercise Options

You can perform this exercise in two ways:

  1. Platform Simulation – follow the step-by-step instructions within the simulation.
  2. Live Environment - by using the instructions provided below, you can perform the steps in the SAP BTP Free Tier account.
Note

We strongly recommend first performing the steps in the Live Environment.

Platform Simulation

Choose the Start Exercise button below to open a simulation of the platform. Then follow the step-by-step instructions to create a service for a deployment.

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 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
      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
      Expand
    2. Apply the service manifest to the cluster.

      Code snippet
      kubectl apply -f hello-kyma-svc.yaml
      Expand
  2. Verify the created service with kubectl.

    Use kubectl to list your services.

    Code snippet
    kubectl get svc
    Expand

    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 the Kyma Dashboard.

    Open up the Kyma Dashboard and navigate to the services view.

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

    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