1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
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+ """
1819
1920from kubernetes import client , config
2021
@@ -32,12 +33,13 @@ def create_deployment_object():
3233 metadata = client .V1ObjectMeta (labels = {"app" : "nginx" }),
3334 spec = client .V1PodSpec (containers = [container ]))
3435 # Create the specification of deployment
35- spec = client .AppsV1beta1DeploymentSpec (
36+ spec = client .V1DeploymentSpec (
3637 replicas = 3 ,
37- template = template )
38+ template = template ,
39+ selector = {'matchLabels' : {'app' : 'nginx' }})
3840 # Instantiate the deployment object
39- deployment = client .AppsV1beta1Deployment (
40- api_version = "apps/v1beta1 " ,
41+ deployment = client .V1Deployment (
42+ api_version = "apps/v1 " ,
4143 kind = "Deployment" ,
4244 metadata = client .V1ObjectMeta (name = DEPLOYMENT_NAME ),
4345 spec = spec )
@@ -80,16 +82,16 @@ def main():
8082 # utility. If no argument provided, the config will be loaded from
8183 # default location.
8284 config .load_kube_config ()
83- apps_v1beta1 = client .AppsV1beta1Api ()
85+ apps_v1 = client .AppsV1Api ()
8486 # Create a deployment object with client-python API. The deployment we
8587 # created is same as the `nginx-deployment.yaml` in the /examples folder.
8688 deployment = create_deployment_object ()
8789
88- create_deployment (apps_v1beta1 , deployment )
90+ create_deployment (apps_v1 , deployment )
8991
90- update_deployment (apps_v1beta1 , deployment )
92+ update_deployment (apps_v1 , deployment )
9193
92- delete_deployment (apps_v1beta1 )
94+ delete_deployment (apps_v1 )
9395
9496
9597if __name__ == '__main__' :
0 commit comments