Skip to content

Instantly share code, notes, and snippets.

@djkonro
Created June 8, 2017 22:43
Show Gist options
  • Save djkonro/2a2d162203e22a09b06cc8ca86a9586a to your computer and use it in GitHub Desktop.
Save djkonro/2a2d162203e22a09b06cc8ca86a9586a to your computer and use it in GitHub Desktop.
from kubernetes import client, config
config.load_kube_config()
# create an instance of the API class
api_instance = client.CoreV1Api()
service = client.V1Service()
service.api_version = 'v1'
service.kind = 'Service'
service.metadata = client.V1ObjectMeta(name='my-service')
spec = client.V1ServiceSpec()
spec.selector = {'app': 'MyApp'}
spec.ports = [client.V1ServicePort(protocol='TCP', port=80, target_port='9376')]
service.spec = spec
api_response = api_instance.create_namespaced_service(namespace='default', body=service)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment