Skip to content

External Service

1. Register a service pointing to your local development environment

During testing stage, it is cumbersome to debug the codes using a deployment.

It's preferred everything is in your local environment, while the k8s sends the resource directly to your local web server.


apiVersion: v1
kind: Service
name: external-service
    - protocol: TCP
    port: 80
    targetPort: 8000
apiVersion: v1
kind: Endpoints
name: external-service
- addresses:
    - ip:
    - port: 8000

Apply the yaml:

$ kubectl apply -f external-endpoint.yaml
endpoints/external-service created
# 🧑🏻‍🎄🧑🏻‍🎄$ kubectl apply -f external-service.yaml
service/external-service created

2. Write a testing web server

Here we use fastapi to write the server and start the server at the local workstation.


from fastapi import FastAPI

app = FastAPI()

async def hello():
    return "Hello, world!"

Run the server:

$ uvicorn main:app --reload --host= --port=8000
INFO:     Will watch for changes in these directories: ['/home/jwang/Documents/Test/fastapi']
INFO:     Uvicorn running on (Press CTRL+C to quit)
INFO:     Started reloader process [4236] using watchgod
INFO:     Started server process [4238]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

3. Test the server by calling k8s service cluster IP

Get the cluster IP of the service by running the commands in the k8s node

$ kubectl -n kserve get svc
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
external-service ClusterIP   <none>        80/TCP     9s

Test the server:

$ curl
"Hello, world!"