Skip to content

Commit c1e5180

Browse files
committed
Use v1 API in the ingress example
1 parent 7f6dbd5 commit c1e5180

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

examples/ingress_create.py

+21-14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def create_deployment(apps_v1_api):
3434
# Spec
3535
spec = client.V1DeploymentSpec(
3636
replicas=1,
37+
selector=client.V1LabelSelector(
38+
match_labels={"app": "deployment"}
39+
),
3740
template=template)
3841
# Deployment
3942
deployment = client.V1Deployment(
@@ -69,23 +72,27 @@ def create_service():
6972
core_v1_api.create_namespaced_service(namespace="default", body=body)
7073

7174

72-
def create_ingress(networking_v1_beta1_api):
73-
body = client.NetworkingV1beta1Ingress(
74-
api_version="networking.k8s.io/v1beta1",
75+
def create_ingress(networking_v1_api):
76+
body = client.V1Ingress(
77+
api_version="networking.k8s.io/v1",
7578
kind="Ingress",
7679
metadata=client.V1ObjectMeta(name="ingress-example", annotations={
7780
"nginx.ingress.kubernetes.io/rewrite-target": "/"
7881
}),
79-
spec=client.NetworkingV1beta1IngressSpec(
80-
rules=[client.NetworkingV1beta1IngressRule(
82+
spec=client.V1IngressSpec(
83+
rules=[client.V1IngressRule(
8184
host="example.com",
82-
http=client.NetworkingV1beta1HTTPIngressRuleValue(
83-
paths=[client.NetworkingV1beta1HTTPIngressPath(
85+
http=client.V1HTTPIngressRuleValue(
86+
paths=[client.V1HTTPIngressPath(
8487
path="/",
85-
backend=client.NetworkingV1beta1IngressBackend(
86-
service_port=5678,
87-
service_name="service-example")
88-
88+
path_type="Exact",
89+
backend=client.V1IngressBackend(
90+
service=client.V1IngressServiceBackend(
91+
port=client.V1ServiceBackendPort(
92+
number=5678,
93+
),
94+
name="service-example")
95+
)
8996
)]
9097
)
9198
)
@@ -94,7 +101,7 @@ def create_ingress(networking_v1_beta1_api):
94101
)
95102
# Creation of the Deployment in specified namespace
96103
# (Can replace "default" with a namespace you may have created)
97-
networking_v1_beta1_api.create_namespaced_ingress(
104+
networking_v1_api.create_namespaced_ingress(
98105
namespace="default",
99106
body=body
100107
)
@@ -104,11 +111,11 @@ def main():
104111
# Fetching and loading local Kubernetes Information
105112
config.load_kube_config()
106113
apps_v1_api = client.AppsV1Api()
107-
networking_v1_beta1_api = client.NetworkingV1beta1Api()
114+
networking_v1_api = client.NetworkingV1Api()
108115

109116
create_deployment(apps_v1_api)
110117
create_service()
111-
create_ingress(networking_v1_beta1_api)
118+
create_ingress(networking_v1_api)
112119

113120

114121
if __name__ == "__main__":

0 commit comments

Comments
 (0)