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
Docker is platform for packaging, distribution and running applications. It allows you to package your application together with its whole environment. This can be either a few libraries that the app requires or even all the files that are usually available on the filesystem of an installed operating system. Docker makes it possible to transfer this package to a central repository from which it can then be transferred to any computer running Docker and executed there
49
+
Docker is a platform for packaging, distribution and running applications. It allows you to package your application together with its whole environment. This can be either a few libraries that the app requires or even all the files that are usually available on the filesystem of an installed operating system. Docker makes it possible to transfer this package to a central repository from which it can then be transferred to any computer running Docker and executed there
16
50
17
51
Three main concepts in Docker comprise this scenario:
18
52
-**Images** :— A Docker based container image is something you package your application and its environment into. It contains the filesystem that will be available to the application and other metadata, such as the path to the executable that should be executed when the image is run.
19
-
-**Registries** :- A Docker Registry is a repository that stores your Docker images and facilitates easy sharing of those images between different people and computers. When you build your image, you can either run it on the computer you’ve built it on, or you can push (upload) the image to a registry and then pull (download) it on another computer and run it there. Certain registries are pub- lic, allowing anyone to pull images from it, while others are private, only accessi- ble to certain people or machines.
20
-
-**Containers** :- A Docker-based container is a regular Linux container created from a Docker-based container image. A running container is a process running on the host running Docker, but it’s completely isolated from both the host and all other processes running on it. The process is also resource-constrained, meaning it can only access and use the amount of resources (CPU, RAM, and so on) that are allocated to it.
53
+
-**Registries** :- A Docker Registry is a repository that stores your Docker images and facilitates easy sharing of those images between different people and computers. When you build your image, you can either run it on the computer you’ve built it on, or you can push (upload) the image to a registry and then pull (download) it on another computer and run it there. Certain registries are public, allowing anyone to pull images from it, while others are private, only accessible to certain people or machines.
54
+
-**Containers** :- A Docker-based container is a regular Linux container created from a Docker-based container image. A running container is a process running on the host running Docker, but it’s completely isolated from both the host and all other processes running on it. The process is also resource-constrained, meaning it can only access and use the number of resources (CPU, RAM, and so on) that are allocated to it.
21
55
22
56
## Learning while working
23
57
58
+
#### Creating a web server
59
+
24
60
You first need to create a container image. We will use docker for that. We are creating a simple web server to see how kubernetes works.
25
61
26
62
- create a file `app.js` and copy this code into it
@@ -39,12 +75,12 @@ www.listen(8080);
39
75
40
76
```
41
77
42
-
Now we will create a docker file that will run on cluster when we create a docker image.
78
+
Now we will create a docker file that will run on a cluster when we create a docker image.
43
79
44
80
- create a file named `Dockerfile` and copy this code into it.
Make sure your **docker server is up and running**. Now we will create a docker image in our local machine. Open your terminal in current project's folder and run
95
+
Make sure your **docker server is up and running**. Now we will create a docker image in our local machine. Open your terminal in the current project's folder and run
60
96
61
97
`docker build -t kubia .`
62
98
63
99
You’re telling Docker to build an image called **kubia** based on the contents of the current directory (note the dot at the end of the build command). Docker will look for the Dockerfile in the directory and build the image based on the instructions in the file.
64
100
65
-
Now check the your docker image created by running
101
+
Now check your docker image created by running
66
102
67
103
#### Getting docker images
68
104
@@ -83,23 +119,23 @@ Run in your terminal
83
119
`curl localhost:8080`
84
120
> You’ve hit 44d76963e8e1
85
121
86
-
#### Lisiting all your running containers
122
+
#### Listing all your running containers
87
123
88
124
You can list all your running containers by this command.
89
125
90
126
`docker ps`
91
127
92
128
The `docker ps` command only shows the most basic information about the containers.
93
129
94
-
Also to get additional infomation about a container run this command
130
+
Also to get additional information about a container run this command
95
131
96
132
`docker inspect kubia-container`
97
133
98
-
You can see all container by
134
+
You can see all the container by
99
135
100
136
`docker ps -a`
101
137
102
-
####Running a shell inside an existing container
138
+
### Running a shell inside an existing container
103
139
104
140
The Node.js image on which you’ve based your image contains the bash shell, so you can run the shell inside the container like this:
You see only three processes. You don’t see any other processes from the host OS.
126
162
127
163
128
-
Like having an isolated process tree, each container also has an isolated filesystem. Listing the contents of the root directory inside the container will only show the files in the container and will include all the files that are in the image plus any files that are created while the container is running (log files and similar), as shown in the fol- lowing listing.
164
+
Like having an isolated process tree, each container also has an isolated filesystem. Listing the contents of the root directory inside the container will only show the files in the container and will include all the files that are in the image plus any files that are created while the container is running (log files and similar), as shown in the following listing.
129
165
130
166
```bash
131
167
root@c61b9b509f9a:/# ls
@@ -138,13 +174,13 @@ It contains the **app.js** file and other system directories that are part of th
138
174
139
175
`docker stop kubia-container`
140
176
141
-
This will stop the main process running in the container and consequently stop the container, because no other processes are running inside the container. The container itself still exists and you can see it with **docker ps -a**. The -a option prints out all the containers, those running and those that have been stopped. To truly remove a container, you need to remove it with the **docker rm** command:
177
+
This will stop the main process running in the container and consequently stop the container because no other processes are running inside the container. The container itself still exists and you can see it with **docker ps -a**. The -a option prints out all the containers, those running and those that have been stopped. To truly remove a container, you need to remove it with the **docker rm** command:
142
178
143
179
`docker rm kubia-container`
144
180
145
181
This deletes the container. All its contents are removed and it can’t be started again.
146
182
147
-
####Pushing the image to an image registry
183
+
### Pushing the image to an image registry
148
184
149
185
The image you’ve built has so far only been available on your local machine. To allow you to run it on any other machine, you need to push the image to an external image registry. For the sake of simplicity, you won’t set up a private image registry and will instead push the image to [Docker Hub](http://hub.docker.com)
150
186
@@ -172,24 +208,24 @@ Now that you have your app packaged inside a container image and made available
172
208
173
209
#### Setting up a Kubernetes cluster
174
210
175
-
Setting up a full-fledged, multi-node Kubernetes cluster isn’t a simple task, especially if you’re not well-versed in Linux and networking administration. A proper Kubernetes install spans multiple physical or virtual machines and requires the networking to be set up properly, so that all the containers running inside the Kubernetes cluster can connect to each other through the same flat networking space.
211
+
Setting up a full-fledged, multi-node Kubernetes cluster isn’t a simple task, especially if you’re not well-versed in Linux and networking administration. A proper Kubernetes install spans multiple physical or virtual machines and requires the networking to be set up properly so that all the containers running inside the Kubernetes cluster can connect to each other through the same flat networking space.
176
212
177
-
####Running a local single-node Kubernetes cluster with Minikube
213
+
### Running a local singlenode Kubernetes cluster with Minikube
178
214
179
215
The simplest and quickest path to a fully functioning Kubernetes cluster is by using Minikube. Minikube is a tool that sets up a single-node cluster that’s great for both testing Kubernetes and developing apps locally.
180
216
181
-
#### Starting a Kubernetes cluster with minkube
217
+
#### Starting a Kubernetes cluster with minikube
182
218
183
219
Once you have Minikube installed locally, you can immediately start up the Kubernetes cluster with the command in the following listing.
184
220
185
221
`minikube start`
186
-
> Starting local Kubernetes cluster...
187
-
188
-
> Starting VM...
189
-
190
-
> SSH-ing files into VM...
191
-
192
-
> Kubectl is now configured to use the cluster.
222
+
```bash
223
+
Starting local Kubernetes cluster...
224
+
Starting VM...
225
+
SSH-ing files into VM...
226
+
...
227
+
Kubectl is now configured to use the cluster.
228
+
```
193
229
194
230
Starting the cluster takes more than a minute, so don’t interrupt the command before
195
231
it completes.
@@ -201,13 +237,17 @@ To interact with Kubernetes, you also need the **kubectl** CLI client. Again, al
201
237
To verify your cluster is working, you can use the **kubectl cluster-info** command shown in the following listing.
202
238
203
239
`kubectl cluster-info`
204
-
> Kubernetes master is running at https://192.168.99.100:8443
240
+
```bash
241
+
Kubernetes master is running at https://192.168.99.100:8443
205
242
206
-
> kubernetes-dashboard is running at https://192.168.99.100:8443/api/v1/...
243
+
kubernetes-dashboard is running at https://192.168.99.100:8443/api/v1/...
244
+
245
+
KubeDNS is running at https://192.168.99.100:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
246
+
```
207
247
208
248
This shows the cluster is up. It shows the URLs of the various Kubernetes components, including the API server and the web console.
209
249
210
-
#### Deploying your Node.js app
250
+
#### Deploying your Node app
211
251
212
252
The simplest way to deploy your app is to use the **kubectl run** command, which will create all the necessary components without having to deal with JSON or YAML.
213
253
@@ -217,7 +257,7 @@ The --image=knrt10/kubia part obviously specifies the container image you want t
217
257
218
258
#### Listing Pods
219
259
220
-
Because you can’t list individual containers, since they’re not standalone Kubernetes objects, can you list pods instead? Yes, you can. Let’s see how to tell kubectl to list pods in the following listing.
260
+
Because you can’t list individual containers since they’re not standalone Kubernetes objects, can you list pods instead? Yes, you can. Let’s see how to tell kubectl to list pods in the following listing.
221
261
222
262
`kubectl get pods`
223
263
@@ -227,9 +267,9 @@ NAME READY STATUS RESTARTS AGE
227
267
kubia-5k788 1/1 Running 1 7d
228
268
```
229
269
230
-
####Accessing your web application
270
+
### Accessing your web application
231
271
232
-
With your pod running, how do you access it? Each pod gets its own IP address, but this address is internal to the cluster and isn’t accessible from outside of it. To make the pod accessible from the outside, you’ll expose it through a Service object. You’ll create a special service of type LoadBalancer, because if you create a regular service (a ClusterIP service), like the pod, it would also only be accessible from inside the cluster. By creating a LoadBalancer-type service, an external load balancer will be created and you can connect to the pod through the load balancer’s public IP.
272
+
With your pod running, how do you access it? Each pod gets its own IP address, but this address is internal to the cluster and isn’t accessible from outside of it. To make the pod accessible from the outside, you’ll expose it through a Service object. You’ll create a special service of type LoadBalancer because if you create a regular service (a ClusterIP service), as the pod, it would also only be accessible from inside the cluster. By creating a LoadBalancer-type service, an external load balancer will be created and you can connect to the pod through the load balancer’s public IP.
233
273
234
274
#### Creating a service object
235
275
@@ -258,7 +298,7 @@ can access the service by running
258
298
259
299
`minikube service kubia-http`
260
300
261
-
####Horizontally scaling the application
301
+
### Horizontally scaling the application
262
302
263
303
You now have a running application, monitored and kept running by a Replication-Controller and exposed to the world through a service. Now let’s make additional magic happen.
264
304
One of the main benefits of using Kubernetes is the simplicity with which you can scale your deployments. Let’s see how easy it is to scale up the number of pods. You’ll increase the number of running instances to three.
@@ -281,7 +321,7 @@ To scale up the number of replicas of your pod, you need to change the desired r
281
321
282
322
You’ve now told Kubernetes to make sure three instances of your pod are always running. Notice that you didn’t instruct Kubernetes what action to take. You didn’t tell it to add two more pods. You only set the new desired number of instances and let Kubernetes determine what actions it needs to take to achieve the requested state.
283
323
284
-
#### Seeing the result of the Scale-out
324
+
#### Seeing the result of the Scale Out
285
325
286
326
Back to your replica count increase. Let’s list the ReplicationControllers again to see the updated replica count:
287
327
@@ -309,7 +349,7 @@ As you can see, scaling an application is incredibly simple. Once your app is ru
309
349
310
350
Keep in mind that the app itself needs to support being scaled horizontally. Kubernetes doesn’t magically make your app scalable; it only makes it trivial to scale the app up or down.
311
351
312
-
#### Displaying the Pod IP and and Pod's Node when listing Pods
352
+
#### Displaying the Pod IP and Pods Node when listing Pods
313
353
314
354
If you’ve been paying close attention, you probably noticed that the **kubectl get pods** command doesn’t even show any information about the nodes the pods are scheduled to. This is because it’s usually not an important piece of information.
0 commit comments