Skip to content

Commit 24bb508

Browse files
committed
added index
1 parent e716405 commit 24bb508

File tree

1 file changed

+77
-37
lines changed

1 file changed

+77
-37
lines changed

readme.md

+77-37
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,62 @@
11
## Learning Kubernetes
22

3-
This is just a simple demonstration to get basic understanding how kubernetes works while working step by step.
3+
This is just a simple demonstration to get a basic understanding of how kubernetes works while working step by step.
4+
5+
## Contents
6+
7+
1. [Requirements](#requirements)
8+
2. **Docker**
9+
- [What is docker](#what-is-docker?)
10+
- [Creating a web server](#creating-a-web-server)
11+
- [Building docker image](#building-docker-image)
12+
- [Getting docker images](#getting-docker-images)
13+
- [Running the container image](#running-the-container-image)
14+
- [Accessing your application](#accessing-your-application)
15+
- [Listing all your running containers](#listing-all-your-running-containers)
16+
- [Running a shell inside an existing container](#running-a-shell-inside-an-existing-container)
17+
- [Exploring container from within](#exploring-container-from-within)
18+
- [Stopping and removing a container](#stopping-and-removing-a-container)
19+
- [Pushing the image to an image registry](#pushing-the-image-to-an-image-registry)
20+
- [Pushing image to docker hub](#pushing-image-to-docker-hub)
21+
3. **Kubernetes**
22+
- [Working with Kubernetes](#working-with-kubernetes)
23+
- [Setting up a Kubernetes cluster](#setting-up-a-kubernetes-cluster)
24+
- [Running a local single node Kubernetes cluster with Minikube](#running-a-local-single-node-kubernetes-cluster-with-minikube)
25+
- [Starting a Kubernetes cluster with minikube](#starting-a-kubernetes-cluster-with-minikube)
26+
- [Checking Status of cluster](#checking-to-see-if-the-cluster-is-up-and-kubernetes-can-talk-to-it)
27+
- [Deploying your Node app](#deploying-your-node-app)
28+
- [Listing Pods](#listing-pods)
29+
- [Accessing your web application](#accessing-your-web-application)
30+
- [Creating a service object](#creating-a-service-object)
31+
- [Listing Services](#listing-services)
32+
- [Horizontally scaling the application](#horizontally-scaling-the-application)
33+
- [Increasing the desired Replica count](#increasing-the-desired-replica-count)
34+
- [Seeing the result of the Scale Out](#seeing-the-result-of-the-scale-out)
35+
- [Displaying the Pod IP and Pods Node when listing Pods](#displaying-the-pod-ip-and-pods-node-when-listing-pods)
36+
- [Accessing Dashboard when using Minikube](#accessing-dashboard-when-using-minikube)
37+
438

539
## Requirements
640

741
- You need to have [docker](https://www.docker.com/) installed for your OS
842
- [minikube](https://github.com/kubernetes/minikube) installed for running locally
943
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/) installed.
1044

11-
## Simple conepts before we start
45+
## Simple concepts before we start
1246

13-
#### What is docker
47+
#### What is docker?
1448

15-
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
1650

1751
Three main concepts in Docker comprise this scenario:
1852
- **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.
2155

2256
## Learning while working
2357

58+
#### Creating a web server
59+
2460
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.
2561

2662
- create a file `app.js` and copy this code into it
@@ -39,12 +75,12 @@ www.listen(8080);
3975

4076
```
4177

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.
4379

4480
- create a file named `Dockerfile` and copy this code into it.
4581

46-
```docker
47-
FROM node:8
82+
```Dockerfile
83+
FROM node:8
4884

4985
RUN npm i
5086

@@ -56,13 +92,13 @@ ENTRYPOINT [ "node", "app.js" ]
5692

5793
#### Building docker image
5894

59-
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
6096

6197
`docker build -t kubia .`
6298

6399
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.
64100

65-
Now check the your docker image created by running
101+
Now check your docker image created by running
66102

67103
#### Getting docker images
68104

@@ -83,23 +119,23 @@ Run in your terminal
83119
`curl localhost:8080`
84120
> You’ve hit 44d76963e8e1
85121
86-
#### Lisiting all your running containers
122+
#### Listing all your running containers
87123

88124
You can list all your running containers by this command.
89125

90126
`docker ps`
91127

92128
The `docker ps` command only shows the most basic information about the containers.
93129

94-
Also to get additional infomation about a container run this command
130+
Also to get additional information about a container run this command
95131

96132
`docker inspect kubia-container`
97133

98-
You can see all container by
134+
You can see all the container by
99135

100136
`docker ps -a`
101137

102-
#### Running a shell inside an existing container
138+
### Running a shell inside an existing container
103139

104140
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:
105141

@@ -125,7 +161,7 @@ root 16 0.0 0.0 17504 2036 pts/0 R+ 06:02 0:00 ps aux
125161
You see only three processes. You don’t see any other processes from the host OS.
126162

127163

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.
129165

130166
```bash
131167
root@c61b9b509f9a:/# ls
@@ -138,13 +174,13 @@ It contains the **app.js** file and other system directories that are part of th
138174

139175
`docker stop kubia-container`
140176

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:
142178

143179
`docker rm kubia-container`
144180

145181
This deletes the container. All its contents are removed and it can’t be started again.
146182

147-
#### Pushing the image to an image registry
183+
### Pushing the image to an image registry
148184

149185
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)
150186

@@ -172,24 +208,24 @@ Now that you have your app packaged inside a container image and made available
172208

173209
#### Setting up a Kubernetes cluster
174210

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.
176212

177-
#### Running a local single-node Kubernetes cluster with Minikube
213+
### Running a local single node Kubernetes cluster with Minikube
178214

179215
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.
180216

181-
#### Starting a Kubernetes cluster with minkube
217+
#### Starting a Kubernetes cluster with minikube
182218

183219
Once you have Minikube installed locally, you can immediately start up the Kubernetes cluster with the command in the following listing.
184220

185221
`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+
```
193229

194230
Starting the cluster takes more than a minute, so don’t interrupt the command before
195231
it completes.
@@ -201,13 +237,17 @@ To interact with Kubernetes, you also need the **kubectl** CLI client. Again, al
201237
To verify your cluster is working, you can use the **kubectl cluster-info** command shown in the following listing.
202238

203239
`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
205242

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+
```
207247

208248
This shows the cluster is up. It shows the URLs of the various Kubernetes components, including the API server and the web console.
209249

210-
#### Deploying your Node.js app
250+
#### Deploying your Node app
211251

212252
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.
213253

@@ -217,7 +257,7 @@ The --image=knrt10/kubia part obviously specifies the container image you want t
217257

218258
#### Listing Pods
219259

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.
221261

222262
`kubectl get pods`
223263

@@ -227,9 +267,9 @@ NAME READY STATUS RESTARTS AGE
227267
kubia-5k788 1/1 Running 1 7d
228268
```
229269

230-
#### Accessing your web application
270+
### Accessing your web application
231271

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.
233273

234274
#### Creating a service object
235275

@@ -258,7 +298,7 @@ can access the service by running
258298

259299
`minikube service kubia-http`
260300

261-
#### Horizontally scaling the application
301+
### Horizontally scaling the application
262302

263303
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.
264304
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
281321
282322
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.
283323

284-
#### Seeing the result of the Scale-out
324+
#### Seeing the result of the Scale Out
285325

286326
Back to your replica count increase. Let’s list the ReplicationControllers again to see the updated replica count:
287327

@@ -309,7 +349,7 @@ As you can see, scaling an application is incredibly simple. Once your app is ru
309349

310350
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.
311351

312-
#### Displaying the Pod IP and and Pod's Node when listing Pods
352+
#### Displaying the Pod IP and Pods Node when listing Pods
313353

314354
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.
315355

0 commit comments

Comments
 (0)