Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use v1 API in the ingress example #1638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions examples/ingress_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ def create_deployment(apps_v1_api):
# Spec
spec = client.V1DeploymentSpec(
replicas=1,
selector=client.V1LabelSelector(
match_labels={"app": "deployment"}
),
template=template)
# Deployment
deployment = client.V1Deployment(
Expand Down Expand Up @@ -69,23 +72,27 @@ def create_service():
core_v1_api.create_namespaced_service(namespace="default", body=body)


def create_ingress(networking_v1_beta1_api):
body = client.NetworkingV1beta1Ingress(
api_version="networking.k8s.io/v1beta1",
def create_ingress(networking_v1_api):
body = client.V1Ingress(
api_version="networking.k8s.io/v1",
kind="Ingress",
metadata=client.V1ObjectMeta(name="ingress-example", annotations={
"nginx.ingress.kubernetes.io/rewrite-target": "/"
}),
spec=client.NetworkingV1beta1IngressSpec(
rules=[client.NetworkingV1beta1IngressRule(
spec=client.V1IngressSpec(
rules=[client.V1IngressRule(
host="example.com",
http=client.NetworkingV1beta1HTTPIngressRuleValue(
paths=[client.NetworkingV1beta1HTTPIngressPath(
http=client.V1HTTPIngressRuleValue(
paths=[client.V1HTTPIngressPath(
path="/",
backend=client.NetworkingV1beta1IngressBackend(
service_port=5678,
service_name="service-example")

path_type="Exact",
backend=client.V1IngressBackend(
service=client.V1IngressServiceBackend(
port=client.V1ServiceBackendPort(
number=5678,
),
name="service-example")
)
)]
)
)
Expand All @@ -94,7 +101,7 @@ def create_ingress(networking_v1_beta1_api):
)
# Creation of the Deployment in specified namespace
# (Can replace "default" with a namespace you may have created)
networking_v1_beta1_api.create_namespaced_ingress(
networking_v1_api.create_namespaced_ingress(
namespace="default",
body=body
)
Expand All @@ -104,11 +111,11 @@ def main():
# Fetching and loading local Kubernetes Information
config.load_kube_config()
apps_v1_api = client.AppsV1Api()
networking_v1_beta1_api = client.NetworkingV1beta1Api()
networking_v1_api = client.NetworkingV1Api()

create_deployment(apps_v1_api)
create_service()
create_ingress(networking_v1_beta1_api)
create_ingress(networking_v1_api)


if __name__ == "__main__":
Expand Down