12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
- from os import path
16
-
17
- import yaml
15
+ """
16
+ This example shows how to work with AppsV1Api to create, modify and delete
17
+ deployments
18
+ """
18
19
19
20
from kubernetes import client , config
20
21
@@ -32,12 +33,13 @@ def create_deployment_object():
32
33
metadata = client .V1ObjectMeta (labels = {"app" : "nginx" }),
33
34
spec = client .V1PodSpec (containers = [container ]))
34
35
# Create the specification of deployment
35
- spec = client .AppsV1beta1DeploymentSpec (
36
+ spec = client .V1DeploymentSpec (
36
37
replicas = 3 ,
37
- template = template )
38
+ template = template ,
39
+ selector = {'matchLabels' : {'app' : 'nginx' }})
38
40
# Instantiate the deployment object
39
- deployment = client .AppsV1beta1Deployment (
40
- api_version = "apps/v1beta1 " ,
41
+ deployment = client .V1Deployment (
42
+ api_version = "apps/v1 " ,
41
43
kind = "Deployment" ,
42
44
metadata = client .V1ObjectMeta (name = DEPLOYMENT_NAME ),
43
45
spec = spec )
@@ -80,16 +82,16 @@ def main():
80
82
# utility. If no argument provided, the config will be loaded from
81
83
# default location.
82
84
config .load_kube_config ()
83
- apps_v1beta1 = client .AppsV1beta1Api ()
85
+ apps_v1 = client .AppsV1Api ()
84
86
# Create a deployment object with client-python API. The deployment we
85
87
# created is same as the `nginx-deployment.yaml` in the /examples folder.
86
88
deployment = create_deployment_object ()
87
89
88
- create_deployment (apps_v1beta1 , deployment )
90
+ create_deployment (apps_v1 , deployment )
89
91
90
- update_deployment (apps_v1beta1 , deployment )
92
+ update_deployment (apps_v1 , deployment )
91
93
92
- delete_deployment (apps_v1beta1 )
94
+ delete_deployment (apps_v1 )
93
95
94
96
95
97
if __name__ == '__main__' :
0 commit comments