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

Skip to content

Commit 2f48377

Browse files
committed
Add example to create a deployment from yaml file
1 parent f10f4f3 commit 2f48377

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

examples/create_deployment.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
from kubernetes import client, config
19+
20+
21+
def main():
22+
# Configs can be set in Configuration class directly or using helper
23+
# utility. If no argument provided, the config will be loaded from
24+
# default location.
25+
config.load_kube_config()
26+
27+
with open(path.join(path.dirname(__file__), "nginx-deployment.yaml")) as f:
28+
dep = yaml.load(f)
29+
k8s_beta = client.ExtensionsV1beta1Api()
30+
resp = k8s_beta.create_namespaced_deployment(
31+
body=dep, namespace="default")
32+
print("Deployment created. status='%s'" % str(resp.status))
33+
34+
35+
if __name__ == '__main__':
36+
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)