Skip to content

Service

Overview

See the official documentation.

Operations

List the services

Current namespace:

kubectl get service

Specific namespace:

kubectl -n ${namespace} get service

All namespaces:

kubectl get -A service

Create a service

Order of operations

A Service is used to expose a Deployment.

If your Service does not seems to work, be sure you have a proper Deployment.

Current namespace:

kubectl apply -f ${file}

Specific namespace:

kubectl -n ${namespace} apply -f ${file}

Example service file (i.e. ${file}):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
---
apiVersion: v1
kind: Service
metadata:
  name: hello-world
  labels:
    app: hello-world
spec:
  ports:
  - name: "http"
    port: 8080
    targetPort: 8080
  selector:
    app: hello-world

Expose a service

See the Ingress documentation.