@@ -34,6 +34,9 @@ def create_deployment(apps_v1_api):
34
34
# Spec
35
35
spec = client .V1DeploymentSpec (
36
36
replicas = 1 ,
37
+ selector = client .V1LabelSelector (
38
+ match_labels = {"app" : "deployment" }
39
+ ),
37
40
template = template )
38
41
# Deployment
39
42
deployment = client .V1Deployment (
@@ -69,23 +72,27 @@ def create_service():
69
72
core_v1_api .create_namespaced_service (namespace = "default" , body = body )
70
73
71
74
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 " ,
75
78
kind = "Ingress" ,
76
79
metadata = client .V1ObjectMeta (name = "ingress-example" , annotations = {
77
80
"nginx.ingress.kubernetes.io/rewrite-target" : "/"
78
81
}),
79
- spec = client .NetworkingV1beta1IngressSpec (
80
- rules = [client .NetworkingV1beta1IngressRule (
82
+ spec = client .V1IngressSpec (
83
+ rules = [client .V1IngressRule (
81
84
host = "example.com" ,
82
- http = client .NetworkingV1beta1HTTPIngressRuleValue (
83
- paths = [client .NetworkingV1beta1HTTPIngressPath (
85
+ http = client .V1HTTPIngressRuleValue (
86
+ paths = [client .V1HTTPIngressPath (
84
87
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
+ )
89
96
)]
90
97
)
91
98
)
@@ -94,7 +101,7 @@ def create_ingress(networking_v1_beta1_api):
94
101
)
95
102
# Creation of the Deployment in specified namespace
96
103
# (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 (
98
105
namespace = "default" ,
99
106
body = body
100
107
)
@@ -104,11 +111,11 @@ def main():
104
111
# Fetching and loading local Kubernetes Information
105
112
config .load_kube_config ()
106
113
apps_v1_api = client .AppsV1Api ()
107
- networking_v1_beta1_api = client .NetworkingV1beta1Api ()
114
+ networking_v1_api = client .NetworkingV1Api ()
108
115
109
116
create_deployment (apps_v1_api )
110
117
create_service ()
111
- create_ingress (networking_v1_beta1_api )
118
+ create_ingress (networking_v1_api )
112
119
113
120
114
121
if __name__ == "__main__" :
0 commit comments