@@ -22,53 +22,93 @@ for database debugging.
22
22
23
23
{% capture steps %}
24
24
25
- ## Creating a pod to run a Redis server
25
+ ## Creating Redis deployment and service
26
26
27
- 1 . Create a pod :
27
+ 1 . Create a Redis deployment :
28
28
29
- kubectl create -f https://k8s.io/docs/tasks/access -application-cluster/ redis-master.yaml
29
+ kubectl create -f https://k8s.io/docs/tutorials/stateless -application/guestbook/ redis-master-deployment .yaml
30
30
31
- The output of a successful command verifies that the pod was created:
31
+ The output of a successful command verifies that the deployment was created:
32
32
33
- pod "redis-master" created
33
+ deployment "redis-master" created
34
+
35
+ When the pod is ready, you can get:
36
+
37
+ kubectl get pods
34
38
35
- 1 . Check to see whether the pod is running and ready:
39
+ NAME READY STATUS RESTARTS AGE
40
+ redis-master-765d459796-258hz 1/1 Running 0 50s
36
41
37
- kubectl get pods
42
+ kubectl get deployment
43
+
44
+ NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
45
+ redis-master 1 1 1 1 55s
46
+
47
+ kubectl get rs
48
+ NAME DESIRED CURRENT READY AGE
49
+ redis-master-765d459796 1 1 1 1m
50
+
51
+
52
+ 2 . Create a Redis service:
53
+
54
+ kubectl create -f https://k8s.io/docs/tutorials/stateless-application/guestbook/redis-master-service.yaml
55
+
56
+ The output of a successful command verifies that the service was created:
57
+
58
+ service "redis-master" created
59
+
60
+ Check the service created:
38
61
39
- When the pod is ready, the output displays a STATUS of Running:
62
+ kubectl get svc | grep redis
40
63
41
- NAME READY STATUS RESTARTS AGE
42
- redis-master 2/2 Running 0 41s
64
+ NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
65
+ redis-master ClusterIP 10.0.0.213 <none> 6379/TCP 27s
43
66
44
- 1 . Verify that the Redis server is running in the pod and listening on port 6379:
67
+ 3 . Verify that the Redis server is running in the pod and listening on port 6379:
45
68
46
69
{% raw %}
47
- kubectl get pods redis-master --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
70
+ kubectl get pods redis-master-765d459796-258hz --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'
48
71
{% endraw %}
49
72
50
73
The output displays the port:
51
74
52
75
6379
53
76
77
+
54
78
## Forward a local port to a port on the pod
55
79
56
- 1 . Forward port 6379 on the local workstation to port 6379 of redis-master pod:
80
+ 1 . ` kubectl port-forward ` allows using resource name, such as a service name, to select a matching pod to port forward to since Kubernetes v1.10.
81
+
82
+ kubectl port-forward redis-master-765d459796-258hz 6379:6379
83
+
84
+ which is the same as
85
+
86
+ kubectl port-forward pods/redis-master-765d459796-258hz 6379:6379
87
+
88
+ or
89
+
90
+ kubectl port-forward deployment/redis-master 6379:6379
91
+
92
+ or
93
+
94
+ kubectl port-forward rs/redis-master 6379:6379
95
+
96
+ or
57
97
58
- kubectl port-forward redis-master 6379:6379
98
+ kubectl port-forward svc/ redis-master 6379:6379
59
99
60
- The output is similar to this:
100
+ Any of the above commands works. The output is similar to this:
61
101
62
102
I0710 14:43:38.274550 3655 portforward.go:225] Forwarding from 127.0.0.1:6379 -> 6379
63
103
I0710 14:43:38.274797 3655 portforward.go:225] Forwarding from [::1]:6379 -> 6379
64
104
65
- 1 . Start the Redis command line interface:
105
+ 2 . Start the Redis command line interface:
66
106
67
- redis-cli
107
+ redis-cli
68
108
69
- 1 . At the Redis command line prompt, enter the ` ping ` command:
109
+ 3 . At the Redis command line prompt, enter the ` ping ` command:
70
110
71
- 127.0.0.1:6379>ping
111
+ 127.0.0.1:6379>ping
72
112
73
113
A successful ping request returns PONG.
74
114
0 commit comments