Skip to content

Commit

Permalink
Update create_deployment notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
djkonro committed Jun 7, 2017
1 parent 1036268 commit 286051a
Showing 1 changed file with 270 additions and 19 deletions.
289 changes: 270 additions & 19 deletions examples/notebooks/create_deployment.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"How to create a Deployment\n",
"==========================\n",
"\n",
"In this notebook, we show you how to create a Deployment with 3 ReplicaSets.\n",
"These ReplicaSets are owned by the Deployment and are managed by the Deployment controller"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": true
},
Expand All @@ -11,49 +22,289 @@
"from kubernetes import client, config"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Load config from default location."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"client.Configuration().host=\"http://localhost:8080\""
"config.load_kube_config()\n",
"extensions = client.ExtensionsV1beta1Api()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create Deployment object"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"extensions = client.ExtensionsV1beta1Api()"
"deployment = client.ExtensionsV1beta1Deployment()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Fill required Deployment fields (apiVersion, kind, and metadata)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"deployment.api_version = 'extensions/v1beta1'\n",
"deployment.kind = 'Deployment'\n",
"deployment.metadata = client.V1ObjectMeta(name='nginx-deployment')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A Deployment also needs a .spec section."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"spec = client.ExtensionsV1beta1DeploymentSpec()\n",
"spec.replicas = 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Add Pod template in .spec.template section"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"body = extensions.V1beta1Deployment()\n",
"namespace = \"default\"\n",
"\n",
"deployment = client.V1beta1Deployment()\n",
"deployment.metadata = client.V1ObjectMeta(name=\"jupyter\")\n",
"spec = client.V1beta1DeploymentSpec()\n",
"spec.template = client.V1PodTemplateSpec()\n",
"spec.template.metadata = client.V1ObjectMeta()\n",
"spec.template.spec = client.V1PodSpec()\n",
"\n",
"\n",
"extensions.create_namespaced_deployment(namespace, body)"
"spec.template.metadata = client.V1ObjectMeta(labels={'app': 'nginx'})\n",
"spec.template.spec = client.V1PodSpec()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pod template container description"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"container = client.V1Container()\n",
"container.name='nginx'\n",
"container.image='nginx:1.7.9'\n",
"container. ports = [client.V1ContainerPort(container_port=80)]"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"spec.template.spec.containers = [container]\n",
"deployment.spec = spec"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Create Deployment"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"{'api_version': 'extensions/v1beta1',\n",
" 'kind': 'Deployment',\n",
" 'metadata': {'annotations': None,\n",
" 'cluster_name': None,\n",
" 'creation_timestamp': datetime.datetime(2017, 6, 3, 16, 34, 23, tzinfo=tzlocal()),\n",
" 'deletion_grace_period_seconds': None,\n",
" 'deletion_timestamp': None,\n",
" 'finalizers': None,\n",
" 'generate_name': None,\n",
" 'generation': 1,\n",
" 'labels': {u'app': 'nginx'},\n",
" 'name': 'nginx-deployment',\n",
" 'namespace': 'default',\n",
" 'owner_references': None,\n",
" 'resource_version': '181854',\n",
" 'self_link': '/apis/extensions/v1beta1/namespaces/default/deployments/nginx-deployment',\n",
" 'uid': '804436c1-487a-11e7-b606-0800277d3a21'},\n",
" 'spec': {'min_ready_seconds': None,\n",
" 'paused': None,\n",
" 'progress_deadline_seconds': None,\n",
" 'replicas': 3,\n",
" 'revision_history_limit': None,\n",
" 'rollback_to': None,\n",
" 'selector': {'match_expressions': None,\n",
" 'match_labels': {u'app': 'nginx'}},\n",
" 'strategy': {'rolling_update': {'max_surge': '1',\n",
" 'max_unavailable': '1'},\n",
" 'type': 'RollingUpdate'},\n",
" 'template': {'metadata': {'annotations': None,\n",
" 'cluster_name': None,\n",
" 'creation_timestamp': None,\n",
" 'deletion_grace_period_seconds': None,\n",
" 'deletion_timestamp': None,\n",
" 'finalizers': None,\n",
" 'generate_name': None,\n",
" 'generation': None,\n",
" 'labels': {u'app': 'nginx'},\n",
" 'name': None,\n",
" 'namespace': None,\n",
" 'owner_references': None,\n",
" 'resource_version': None,\n",
" 'self_link': None,\n",
" 'uid': None},\n",
" 'spec': {'active_deadline_seconds': None,\n",
" 'affinity': None,\n",
" 'automount_service_account_token': None,\n",
" 'containers': [{'args': None,\n",
" 'command': None,\n",
" 'env': None,\n",
" 'env_from': None,\n",
" 'image': 'nginx:1.7.9',\n",
" 'image_pull_policy': 'IfNotPresent',\n",
" 'lifecycle': None,\n",
" 'liveness_probe': None,\n",
" 'name': 'nginx',\n",
" 'ports': [{'container_port': 80,\n",
" 'host_ip': None,\n",
" 'host_port': None,\n",
" 'name': None,\n",
" 'protocol': 'TCP'}],\n",
" 'readiness_probe': None,\n",
" 'resources': {'limits': None,\n",
" 'requests': None},\n",
" 'security_context': None,\n",
" 'stdin': None,\n",
" 'stdin_once': None,\n",
" 'termination_message_path': '/dev/termination-log',\n",
" 'termination_message_policy': None,\n",
" 'tty': None,\n",
" 'volume_mounts': None,\n",
" 'working_dir': None}],\n",
" 'dns_policy': 'ClusterFirst',\n",
" 'host_ipc': None,\n",
" 'host_network': None,\n",
" 'host_pid': None,\n",
" 'hostname': None,\n",
" 'image_pull_secrets': None,\n",
" 'init_containers': None,\n",
" 'node_name': None,\n",
" 'node_selector': None,\n",
" 'restart_policy': 'Always',\n",
" 'scheduler_name': None,\n",
" 'security_context': {'fs_group': None,\n",
" 'run_as_non_root': None,\n",
" 'run_as_user': None,\n",
" 'se_linux_options': None,\n",
" 'supplemental_groups': None},\n",
" 'service_account': None,\n",
" 'service_account_name': None,\n",
" 'subdomain': None,\n",
" 'termination_grace_period_seconds': 30,\n",
" 'tolerations': None,\n",
" 'volumes': None}}},\n",
" 'status': {'available_replicas': None,\n",
" 'conditions': None,\n",
" 'observed_generation': None,\n",
" 'ready_replicas': None,\n",
" 'replicas': None,\n",
" 'unavailable_replicas': None,\n",
" 'updated_replicas': None}}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"extensions.create_namespaced_deployment(namespace='default', body=deployment)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Delete Deployment"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#extensions.delete_namespaced_deployment(name='nginx-deployment', namespace='default', body=client.V1DeleteOptions(),grace_period_seconds = 56, propagation_policy = \"Background\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -72,9 +323,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 2
}

0 comments on commit 286051a

Please sign in to comment.