Add example to create a deployment from yaml file
This commit is contained in:
parent
6593d3a43f
commit
68e3231a80
37
examples/create_deployment.py
Normal file
37
examples/create_deployment.py
Normal file
@ -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()
|
||||
17
examples/nginx-deployment.yaml
Normal file
17
examples/nginx-deployment.yaml
Normal file
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user