From 68e3231a80d235d3909598ef321da3a8bae6d5ac Mon Sep 17 00:00:00 2001 From: mbohlool Date: Tue, 24 Jan 2017 16:12:47 -0800 Subject: [PATCH] Add example to create a deployment from yaml file --- examples/create_deployment.py | 37 ++++++++++++++++++++++++++++++++++ examples/nginx-deployment.yaml | 17 ++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 examples/create_deployment.py create mode 100644 examples/nginx-deployment.yaml diff --git a/examples/create_deployment.py b/examples/create_deployment.py new file mode 100644 index 0000000000..01efeff010 --- /dev/null +++ b/examples/create_deployment.py @@ -0,0 +1,37 @@ +# Copyright 2016 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from os import path + +import yaml + +from kubernetes import client, config + + +def main(): + # Configs can be set in Configuration class directly or using helper + # utility. If no argument provided, the config will be loaded from + # default location. + config.load_kube_config() + + with open(path.join(path.dirname(__file__), "nginx-deployment.yaml")) as f: + dep = yaml.load(f) + k8s_beta = client.ExtensionsV1beta1Api() + resp = k8s_beta.create_namespaced_deployment( + body=dep, namespace="default") + print("Deployment created. status='%s'" % str(resp.status)) + + +if __name__ == '__main__': + main() diff --git a/examples/nginx-deployment.yaml b/examples/nginx-deployment.yaml new file mode 100644 index 0000000000..d05940d29b --- /dev/null +++ b/examples/nginx-deployment.yaml @@ -0,0 +1,17 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: nginx-deployment +spec: + replicas: 3 + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.7.9 + ports: + - containerPort: 80 +