You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>When you deploy applications on Kubernetes, you tell the control plane to start the application containers. The control plane schedules the containers to run on the cluster's nodes. <b>The nodes communicate with the control plane using the <ahref="/docs/concepts/overview/kubernetes-api/">Kubernetes API</a></b>, which the control plane exposes. End users can also use the Kubernetes API directly to interact with the cluster.</p>
86
90
87
-
<p>A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems. The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete. For this tutorial, however, you'll use a provided online terminal with Minikube pre-installed.</p>
91
+
<p>A Kubernetes cluster can be deployed on either physical or virtual machines. To get started with Kubernetes development, you can use Minikube. Minikube is a lightweight Kubernetes implementation that creates a VM on your local machine and deploys a simple cluster containing only one node. Minikube is available for Linux, macOS, and Windows systems. The Minikube CLI provides basic bootstrapping operations for working with your cluster, including start, stop, status, and delete.</p>
92
+
93
+
<p>Now that you know more about what Kubernetes is, visit <ahref="/docs/tutorials/hello-minikube/">Hello Minikube</a>
94
+
to try this out on your computer.</p>
88
95
89
-
<p>Now that you know what Kubernetes is, let's go to the online tutorial and start our first cluster!</p>
<p>Once you've done that, move on to <ahref="/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/">Using <tt>kubectl</tt> to create a Deployment</a>.</p>
Copy file name to clipboardExpand all lines: content/en/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro.html
+67-14Lines changed: 67 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
---
2
2
title: Using kubectl to Create a Deployment
3
3
weight: 10
4
+
description: |-
5
+
Learn about application Deployments.
6
+
Deploy your first app on Kubernetes with kubectl.
4
7
---
5
8
6
9
<!DOCTYPE html>
@@ -14,26 +17,25 @@
14
17
<mainclass="content">
15
18
16
19
<divclass="row">
17
-
18
20
<divclass="col-md-8">
19
21
<h3>Objectives</h3>
20
-
<ul>
21
-
<li>Learn about application Deployments.</li>
22
-
<li>Deploy your first app on Kubernetes with kubectl.</li>
23
-
</ul>
24
-
</div>
22
+
<ul>
23
+
<li>Learn about application Deployments.</li>
24
+
<li>Deploy your first app on Kubernetes with kubectl.</li>
25
+
</ul>
26
+
</div>
25
27
26
28
<divclass="col-md-8">
27
29
<h3>Kubernetes Deployments</h3>
28
30
<p>
29
-
Once you have a running Kubernetes cluster, you can deploy your containerized applications on top of it.
30
-
To do so, you create a Kubernetes <b>Deployment</b> configuration. The Deployment instructs Kubernetes
31
+
Once you have a <ahref="/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/">running Kubernetes cluster</a>, you can deploy your containerized applications on top of it.
32
+
To do so, you create a Kubernetes <b>Deployment</b>. The Deployment instructs Kubernetes
31
33
how to create and update instances of your application. Once you've created a Deployment, the Kubernetes
32
34
control plane schedules the application instances included in that Deployment to run on individual Nodes in the
33
35
cluster.
34
36
</p>
35
37
36
-
<p>Once the application instances are created, a Kubernetes Deployment Controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. <b>This provides a self-healing mechanism to address machine failure or maintenance.</b></p>
38
+
<p>Once the application instances are created, a Kubernetes Deployment controller continuously monitors those instances. If the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster. <b>This provides a self-healing mechanism to address machine failure or maintenance.</b></p>
37
39
38
40
<p>In a pre-orchestration world, installation scripts would often be used to start applications, but they did not allow recovery from machine failure. By both creating your application instances and keeping them running across Nodes, Kubernetes Deployments provide a fundamentally different approach to application management. </p>
39
41
@@ -72,7 +74,7 @@ <h2 style="color: #3771e3;">Deploying your first app on Kubernetes</h2>
72
74
<divclass="row">
73
75
<divclass="col-md-8">
74
76
75
-
<p>You can create and manage a Deployment by using the Kubernetes command line interface, <b>Kubectl</b>. Kubectl uses the Kubernetes API to interact with the cluster. In this module, you'll learn the most common Kubectl commands needed to create Deployments that run your applications on a Kubernetes cluster.</p>
77
+
<p>You can create and manage a Deployment by using the Kubernetes command line interface, <b>kubectl</b>. Kubectl uses the Kubernetes API to interact with the cluster. In this module, you'll learn the most common Kubectl commands needed to create Deployments that run your applications on a Kubernetes cluster.</p>
76
78
77
79
<p>When you create a Deployment, you'll need to specify the container image for your application and the number of replicas that you want to run. You can change that information later by updating your Deployment; Modules <ahref="/docs/tutorials/kubernetes-basics/scale/scale-intro/">5</a> and <ahref="/docs/tutorials/kubernetes-basics/update/update-intro/">6</a> of the bootcamp discuss how you can scale and update your Deployments.</p>
78
80
@@ -91,18 +93,69 @@ <h2 style="color: #3771e3;">Deploying your first app on Kubernetes</h2>
91
93
<divclass="col-md-8">
92
94
<p>
93
95
For your first Deployment, you'll use a hello-node application packaged in a Docker container that uses NGINX to echo back all the requests. (If you didn't already try creating a hello-node application and deploying it using a container, you can do that first by following the instructions from the <ahref="/docs/tutorials/hello-minikube/">Hello Minikube tutorial</a>).
94
-
<p>
95
-
96
-
<p>Now that you know what Deployments are, let's go to the online tutorial and deploy our first app!</p>
96
+
<p>You will need to have installed kubectl as well. If you need to install it, visit <ahref="/docs/tasks/tools/#kubectl">install tools</a>.</p>
97
+
<p>Now that you know what Deployments are, let's deploy our first app!</p>
97
98
</div>
98
99
</div>
99
100
<br>
100
101
102
+
<divclass="row">
103
+
<divclass="col-md-8">
104
+
<h3>kubectl basics</h3>
105
+
<p>The common format of a kubectl command is: <code>kubectl <i>action resource</i></code></p>
106
+
<p>This performs the specified <em>action</em> (like create, describe or delete) on the specified <em>resource</em> (like <tt>node</tt> or <tt>deployment</tt>). You can use <code>-<span/>-help</code> after the subcommand to get additional info about possible parameters (for example: <code>kubectl get nodes --help</code>).</p>
107
+
<p>Check that kubectl is configured to talk to your cluster, by running the <b><code>kubectl version</code></b> command.</p>
108
+
<p>Check that kubectl is installed and you can see both the client and the server versions.</p>
109
+
<p>To view the nodes in the cluster, run the <b><code>kubectl get nodes</code></b> command.</p>
110
+
<p>You see the available nodes. Later, Kubernetes will choose where to deploy our application based on Node available resources.</p>
<p>Let’s deploy our first app on Kubernetes with the <code>kubectl create deployment</code> command. We need to provide the deployment name and app image location (include the full repository url for images hosted outside Docker hub).</p>
<p>Great! You just deployed your first application by creating a deployment. This performed a few things for you:</p>
119
+
<ul>
120
+
<li>searched for a suitable node where an instance of the application could be run (we have only 1 available node)</li>
121
+
<li>scheduled the application to run on that Node</li>
122
+
<li>configured the cluster to reschedule the instance on a new Node when needed</li>
123
+
</ul>
124
+
<p>To list your deployments use the <code>kubectl get deployments</code> command:</p>
125
+
<p><b><code>kubectl get deployments</code></b></p>
126
+
<p>We see that there is 1 deployment running a single instance of your app. The instance is running inside a container on your node.</p>
104
127
</div>
105
128
</div>
129
+
<divclass="row">
130
+
<divclass="col-md-12">
131
+
<h3>View the app</h3>
132
+
<p>Pods that are running inside Kubernetes are running on a private, isolated network.
133
+
By default they are visible from other pods and services within the same kubernetes cluster, but not outside that network.
134
+
When we use <code>kubectl</code>, we're interacting through an API endpoint to communicate with our application.</p>
135
+
<p>We will cover other options on how to expose your application outside the kubernetes cluster in Module 4.</p>
136
+
<p>The <code>kubectl</code> command can create a proxy that will forward communications into the cluster-wide, private network. The proxy can be terminated by pressing control-C and won't show any output while its running. </p>
137
+
<p><strong>You need to open a second terminal window to run the proxy.</strong></p>
138
+
<p><b><code>kubectl proxy</b></code>
139
+
<p>We now have a connection between our host (the online terminal) and the Kubernetes cluster. The proxy enables direct access to the API from these terminals.</p>
140
+
<p>You can see all those APIs hosted through the proxy endpoint. For example, we can query the version directly through the API using the <code>curl</code> command:</p>
<divclass="alert alert-info note callout" role="alert"><strong>Note:</strong> If Port 8001 is not accessible, ensure that the <code>kubectl proxy</code> that you started above is running in the second terminal.</div>
143
+
<p>The API server will automatically create an endpoint for each pod, based on the pod name, that is also accessible through the proxy.</p>
144
+
<p>First we need to get the Pod name, and we'll store in the environment variable <tt>POD_NAME</tt>:</p>
145
+
<p><b><code>export POD_NAME=$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')</code></b><br/>
146
+
<b><code>echo Name of the Pod: $POD_NAME</code></b></p>
147
+
<p>You can access the Pod through the proxied API, by running:</p>
<p>In order for the new Deployment to be accessible without using the proxy, a Service is required which will be explained in the next modules.</p>
150
+
</div>
151
+
152
+
</div>
153
+
<divclass="row">
154
+
<p>
155
+
Once you're ready, move on to <ahref="/docs/tutorials/kubernetes-basics/explore/explore-intro/" title="Viewing Pods and Nodes">Viewing Pods and Nodes</a>.</p>
0 commit comments