@@ -45,15 +45,22 @@ probably debugging your own Service you can substitute your own details, or you
45
45
can follow along and get a second data point.
46
46
47
47
``` shell
48
- kubectl run hostnames --image=k8s.gcr.io/serve_hostname \
49
- --replicas=3
48
+ kubectl create deployment hostnames --image=k8s.gcr.io/serve_hostname
50
49
```
51
50
``` none
52
51
deployment.apps/hostnames created
53
52
```
54
53
55
54
` kubectl ` commands will print the type and name of the resource created or mutated, which can then be used in subsequent commands.
56
55
56
+ Let's scale the deployment to 3 replicas.
57
+ ``` shell
58
+ kubectl scale deployment hostnames --replicas=3
59
+ ```
60
+ ``` none
61
+ deployment.apps/hostnames scaled
62
+ ```
63
+
57
64
{{< note >}}
58
65
This is the same as if you had started the Deployment with the following
59
66
YAML:
@@ -62,30 +69,32 @@ YAML:
62
69
apiVersion : apps/v1
63
70
kind : Deployment
64
71
metadata :
72
+ labels :
73
+ app : hostnames
65
74
name : hostnames
66
75
spec :
67
76
selector :
68
77
matchLabels :
69
- run : hostnames
78
+ app : hostnames
70
79
replicas : 3
71
80
template :
72
81
metadata :
73
82
labels :
74
- run : hostnames
83
+ app : hostnames
75
84
spec :
76
85
containers :
77
86
- name : hostnames
78
87
image : k8s.gcr.io/serve_hostname
79
88
` ` `
80
89
81
- The label "run " is automatically set by ` kubectl run ` to the name of the
90
+ The label "app " is automatically set by ` kubectl create deployment ` to the name of the
82
91
Deployment.
83
92
{{< /note >}}
84
93
85
94
You can confirm your Pods are running :
86
95
87
96
` ` ` shell
88
- kubectl get pods -l run =hostnames
97
+ kubectl get pods -l app =hostnames
89
98
` ` `
90
99
` ` ` none
91
100
NAME READY STATUS RESTARTS AGE
@@ -98,7 +107,7 @@ You can also confirm that your Pods are serving. You can get the list of
98
107
Pod IP addresses and test them directly.
99
108
100
109
` ` ` shell
101
- kubectl get pods -l run =hostnames \
110
+ kubectl get pods -l app =hostnames \
102
111
-o go-template='{{range .items}}{{.status.podIP}}{{"\n "}}{{end}}'
103
112
` ` `
104
113
` ` ` none
122
131
This should produce something like :
123
132
124
133
` ` `
125
- hostnames-0uton
126
- hostnames-bvc05
127
- hostnames-yp2kp
134
+ hostnames-632524106-bbpiw
135
+ hostnames-632524106-ly40y
136
+ hostnames-632524106-tlaok
128
137
` ` `
129
138
130
139
If you are not getting the responses you expect at this point, your Pods
@@ -193,10 +202,12 @@ As before, this is the same as if you had started the Service with YAML:
193
202
apiVersion: v1
194
203
kind: Service
195
204
metadata:
205
+ labels:
206
+ app: hostnames
196
207
name: hostnames
197
208
spec:
198
209
selector:
199
- run : hostnames
210
+ app : hostnames
200
211
ports:
201
212
- name: default
202
213
protocol: TCP
345
356
This should produce something like :
346
357
347
358
` ` `
348
- hostnames-0uton
349
- hostnames-bvc05
350
- hostnames-yp2kp
359
+ hostnames-632524106-bbpiw
360
+ hostnames-632524106-ly40y
361
+ hostnames-632524106-tlaok
351
362
` ` `
352
363
353
364
If your Service is working, you should get correct responses. If not, there
@@ -373,7 +384,7 @@ kubectl get service hostnames -o json
373
384
"resourceVersion": "347189",
374
385
"creationTimestamp": "2015-07-07T15:24:29Z",
375
386
"labels": {
376
- "run ": "hostnames"
387
+ "app ": "hostnames"
377
388
}
378
389
},
379
390
"spec": {
@@ -387,7 +398,7 @@ kubectl get service hostnames -o json
387
398
}
388
399
],
389
400
"selector": {
390
- "run ": "hostnames"
401
+ "app ": "hostnames"
391
402
},
392
403
"clusterIP": "10.0.1.175",
393
404
"type": "ClusterIP",
@@ -414,16 +425,16 @@ actually being selected by the Service.
414
425
Earlier you saw that the Pods were running. You can re-check that :
415
426
416
427
` ` ` shell
417
- kubectl get pods -l run =hostnames
428
+ kubectl get pods -l app =hostnames
418
429
` ` `
419
430
` ` ` none
420
431
NAME READY STATUS RESTARTS AGE
421
- hostnames-0uton 1/1 Running 0 1h
422
- hostnames-bvc05 1/1 Running 0 1h
423
- hostnames-yp2kp 1/1 Running 0 1h
432
+ hostnames-632524106-bbpiw 1/1 Running 0 1h
433
+ hostnames-632524106-ly40y 1/1 Running 0 1h
434
+ hostnames-632524106-tlaok 1/1 Running 0 1h
424
435
` ` `
425
436
426
- The `-l run =hostnames` argument is a label selector - just like our Service
437
+ The `-l app =hostnames` argument is a label selector - just like our Service
427
438
has.
428
439
429
440
The "AGE" column says that these Pods are about an hour old, which implies that
@@ -448,7 +459,8 @@ your Service. If the `ENDPOINTS` column is `<none>`, you should check that
448
459
the `spec.selector` field of your Service actually selects for
449
460
` metadata.labels` values on your Pods. A common mistake is to have a typo or
450
461
other error, such as the Service selecting for `app=hostnames`, but the
451
- Deployment specifying `run=hostnames`.
462
+ Deployment specifying `run=hostnames`, as in versions previous to 1.18, where
463
+ the `kubectl run` command could have been also used to create a Deployment.
452
464
453
465
# # Are the Pods working?
454
466
473
485
This should produce something like :
474
486
475
487
` ` `
476
- hostnames-0uton
477
- hostnames-bvc05
478
- hostnames-yp2kp
488
+ hostnames-632524106-bbpiw
489
+ hostnames-632524106-ly40y
490
+ hostnames-632524106-tlaok
479
491
` ` `
480
492
481
493
You expect each Pod in the Endpoints list to return its own hostname. If
@@ -617,7 +629,7 @@ IP from one of your Nodes:
617
629
curl 10.0.1.175:80
618
630
` ` `
619
631
` ` ` none
620
- hostnames-0uton
632
+ hostnames-632524106-bbpiw
621
633
` ` `
622
634
623
635
If this fails and you are using the userspace proxy, you can try accessing the
@@ -631,7 +643,7 @@ examples it is "48577". Now connect to that:
631
643
curl localhost:48577
632
644
` ` `
633
645
` ` ` none
634
- hostnames-yp2kp
646
+ hostnames-632524106-tlaok
635
647
` ` `
636
648
637
649
If this still fails, look at the `kube-proxy` logs for specific lines like :
0 commit comments