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
Copy file name to clipboardExpand all lines: readme.md
+109Lines changed: 109 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -220,3 +220,112 @@ The --image=knrt10/kubia part obviously specifies the container image you want t
220
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.
221
221
222
222
`kubectl get pods`
223
+
224
+
```bash
225
+
$ kubectl get pods
226
+
NAME READY STATUS RESTARTS AGE
227
+
kubia-5k788 1/1 Running 1 7d
228
+
```
229
+
230
+
#### Accessing your web application
231
+
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.
233
+
234
+
#### Creating a service object
235
+
236
+
To create the service, you’ll tell Kubernetes to expose the ReplicationController you created earlier:
**Important:** We’re using the abbreviation `rc` instead of `replicationcontroller`. Most resource types have an abbreviation like this so you don’t have to type the full name (for example, `po` for `pods`, `svc` for `services`, and so on).
243
+
244
+
#### Listing Services
245
+
246
+
The expose command’s output mentions a service called `kubia-http`. Services are objects like Pods and Nodes, so you can see the newly created Service object by running the **kubectl get services | svc** command, as shown in the following listing.
**Important** :- Minikube doesn’t support LoadBalancer services, so the service will never get an external IP. But you can access the service anyway through its external port. So external IP will always be pending in that case. When using Minikube, you can get the IP and port through which you
257
+
can access the service by running
258
+
259
+
`minikube service kubia-http`
260
+
261
+
#### Horizontally scaling the application
262
+
263
+
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
+
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.
265
+
266
+
Your pod is managed by a ReplicationController. Let’s see it with the kubectl get command:
267
+
268
+
`kubectl get rc`
269
+
270
+
```bash
271
+
NAME DESIRED CURRENT READY AGE
272
+
kubia 1 1 1 7d
273
+
```
274
+
275
+
#### Increasing the desired Replica count
276
+
277
+
To scale up the number of replicas of your pod, you need to change the desired replica count on the ReplicationController like this:
278
+
279
+
`kubectl scale rc kubia --replicas=3`
280
+
> replicationcontroller "kubia" scaled
281
+
282
+
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
+
284
+
#### Seeing the result of the Scale-out
285
+
286
+
Back to your replica count increase. Let’s list the ReplicationControllers again to see the updated replica count:
287
+
288
+
`kubectl get rc`
289
+
290
+
```bash
291
+
NAME DESIRED CURRENT READY AGE
292
+
kubia 3 3 3 7d
293
+
```
294
+
295
+
Because the actual number of pods has already been increased to three (as evident from the CURRENT column), listing all the pods should now show three pods instead of one:
296
+
297
+
`kubectl get pods`
298
+
299
+
```bash
300
+
NAME READY STATUS RESTARTS AGE
301
+
kubia-5k788 1/1 Running 1 7d
302
+
kubia-7zxwj 1/1 Running 1 3d
303
+
kubia-bsksp 1/1 Running 1 3d
304
+
```
305
+
306
+
As you can see, three pods exist instead of one. Currently running, but if it is pending, it would be ready in a few moments, as soon as the container image is downloaded and the container is started.
307
+
308
+
As you can see, scaling an application is incredibly simple. Once your app is running in production and a need to scale the app arises, you can add additional instances with a single command without having to install and run additional copies manually.
309
+
310
+
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
+
312
+
#### Displaying the Pod IP and and Pod's Node when listing Pods
313
+
314
+
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.
315
+
316
+
But you can request additional columns to display using the **-o wide** option. When listing pods, this option shows the pod’s IP and the node the pod is running on:
317
+
318
+
`kubectl get pods -o wide`
319
+
320
+
```bash
321
+
NAME READY STATUS RESTARTS AGE IP NODE
322
+
kubia-5k788 1/1 Running 1 7d 172.17.0.4 minikube
323
+
kubia-7zxwj 1/1 Running 1 3d 172.17.0.5 minikube
324
+
kubia-bsksp 1/1 Running 1 3d 172.17.0.6 minikube
325
+
```
326
+
327
+
#### Accessing Dashboard when using Minikube
328
+
329
+
To open the dashboard in your browser when using Minikube to run your Kubernetes cluster, run the following command:
0 commit comments