Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68e3231

Browse files
committed
Add example to create a deployment from yaml file
1 parent 6593d3a commit 68e3231

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

examples/create_deployment.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2016 The Kubernetes Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from os import path
16+
17+
import yaml
18+
19+
from kubernetes import client, config
20+
21+
22+
def main():
23+
# Configs can be set in Configuration class directly or using helper
24+
# utility. If no argument provided, the config will be loaded from
25+
# default location.
26+
config.load_kube_config()
27+
28+
with open(path.join(path.dirname(__file__), "nginx-deployment.yaml")) as f:
29+
dep = yaml.load(f)
30+
k8s_beta = client.ExtensionsV1beta1Api()
31+
resp = k8s_beta.create_namespaced_deployment(
32+
body=dep, namespace="default")
33+
print("Deployment created. status='%s'" % str(resp.status))
34+
35+
36+
if __name__ == '__main__':
37+
main()

examples/nginx-deployment.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: nginx-deployment
5+
spec:
6+
replicas: 3
7+
template:
8+
metadata:
9+
labels:
10+
app: nginx
11+
spec:
12+
containers:
13+
- name: nginx
14+
image: nginx:1.7.9
15+
ports:
16+
- containerPort: 80
17+

0 commit comments

Comments
 (0)