In this notebook, we show you how to create a Service. A service is a key Kubernetes API resource. It defines a networking abstraction to route traffic to a particular set of Pods using a label selection.
In [ ]:
from kubernetes import client, config
In [ ]:
config.load_kube_config()
In [ ]:
api_instance = client.CoreV1Api()
In [ ]:
service = client.V1Service()
In [ ]:
service.api_version = "v1"
service.kind = "Service"
service.metadata = client.V1ObjectMeta(name="my-service")
In [ ]:
spec = client.V1ServiceSpec()
spec.selector = {"app": "MyApp"}
spec.ports = [client.V1ServicePort(protocol="TCP", port=80, target_port=9376)]
service.spec = spec
In [ ]:
api_instance.create_namespaced_service(namespace="default", body=service)
In [ ]:
api_instance.delete_namespaced_service(name="my-service", namespace="default")
In [ ]: