Creating Services in Kubernetes

Objective

After completing this lesson, you will be able to create a Service in Kubernetes

Creating a Service for a Deployment

Usage 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.

Task Flow

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 if the Service is successfully created using kubectl.
  3. Verify if the Service is successfully created using Kyma dashboard.

Prerequisites

Before you begin, ensure that the following prerequisites are met:

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' ports: - protocol: 'TCP' port: 80 targetPort: 8080
    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

    The hello-kyma-svc Service appears in the list. Choose it to see the details.

    Service Resource Graph

    The next exercise shows how to expose a Service to the outside world.

Result

You have successfully created a Service for the Deployment.