Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

Minikube Guide

正如其名,minikube快速的安装一个k8s的集群,方便新手和应用开发人员调试等。

注:如果资源足够的话,搭建一个kubeadm的集群来的好一些。

官网文档

下载

1
2
3
4
5
6
7
8
9
10
11
# 墙外下载
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

# 上传
[ec2-user@amazonlinux ~]$ rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring minikube-linux-amd64...
  100%   70948 KB    35474 KB/sec    00:00:02       0 Errors  

[ec2-user@amazonlinux ~]$ sudo install minikube-linux-amd64 /usr/local/bin/minikube

安装docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
[ec2-user@amazonlinux ~]$ sudo amazon-linux-extras install docker
Installing docker
Loaded plugins: langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker
12 metadata files removed
4 sqlite files removed
0 metadata files removed
Loaded plugins: langpacks, priorities, update-motd
amzn2-core                                                                                                                                        | 3.7 kB  00:00:00     
amzn2extra-docker                                                                                                                                 | 3.0 kB  00:00:00     
(1/5): amzn2-core/2/x86_64/group_gz                                                                                                               | 2.5 kB  00:00:01     
(2/5): amzn2-core/2/x86_64/updateinfo                                                                                                             | 452 kB  00:00:01     
(3/5): amzn2extra-docker/2/x86_64/updateinfo                                                                                                      | 5.9 kB  00:00:00     
(4/5): amzn2extra-docker/2/x86_64/primary_db                                                                                                      |  86 kB  00:00:01     
(5/5): amzn2-core/2/x86_64/primary_db                                                                                                             |  60 MB  00:00:04     
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:20.10.7-5.amzn2 will be installed
--> Processing Dependency: runc >= 1.0.0 for package: docker-20.10.7-5.amzn2.x86_64
--> Processing Dependency: libcgroup >= 0.40.rc1-5.15 for package: docker-20.10.7-5.amzn2.x86_64
--> Processing Dependency: containerd >= 1.3.2 for package: docker-20.10.7-5.amzn2.x86_64
--> Processing Dependency: pigz for package: docker-20.10.7-5.amzn2.x86_64
--> Running transaction check
---> Package containerd.x86_64 0:1.4.6-8.amzn2 will be installed
---> Package libcgroup.x86_64 0:0.41-21.amzn2 will be installed
---> Package pigz.x86_64 0:2.3.4-1.amzn2.0.1 will be installed
---> Package runc.x86_64 0:1.0.0-2.amzn2 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================
 Package                               Arch                              Version                                      Repository                                    Size
=========================================================================================================================================================================
Installing:
 docker                                x86_64                            20.10.7-5.amzn2                              amzn2extra-docker                             42 M
Installing for dependencies:
 containerd                            x86_64                            1.4.6-8.amzn2                                amzn2extra-docker                             24 M
 libcgroup                             x86_64                            0.41-21.amzn2                                amzn2-core                                    66 k
 pigz                                  x86_64                            2.3.4-1.amzn2.0.1                            amzn2-core                                    81 k
 runc                                  x86_64                            1.0.0-2.amzn2                                amzn2extra-docker                            3.3 M

Transaction Summary
=========================================================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 69 M
Installed size: 285 M
Is this ok [y/d/N]: t
Is this ok [y/d/N]: y
Downloading packages:
(1/5): libcgroup-0.41-21.amzn2.x86_64.rpm                                                                                                         |  66 kB  00:00:01     
(2/5): pigz-2.3.4-1.amzn2.0.1.x86_64.rpm                                                                                                          |  81 kB  00:00:01     
(3/5): docker-20.10.7-5.amzn2.x86_64.rpm                                                                                                          |  42 MB  00:00:07     
(4/5): runc-1.0.0-2.amzn2.x86_64.rpm                                                                                                              | 3.3 MB  00:00:00     
(5/5): containerd-1.4.6-8.amzn2.x86_64.rpm                                                                                                        |  24 MB  00:00:12     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                    5.5 MB/s |  69 MB  00:00:12     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : runc-1.0.0-2.amzn2.x86_64                                                                                                                             1/5 
  Installing : containerd-1.4.6-8.amzn2.x86_64                                                                                                                       2/5 
  Installing : libcgroup-0.41-21.amzn2.x86_64                                                                                                                        3/5 
  Installing : pigz-2.3.4-1.amzn2.0.1.x86_64                                                                                                                         4/5 
  Installing : docker-20.10.7-5.amzn2.x86_64                                                                                                                         5/5 
  Verifying  : docker-20.10.7-5.amzn2.x86_64                                                                                                                         1/5 
  Verifying  : containerd-1.4.6-8.amzn2.x86_64                                                                                                                       2/5 
  Verifying  : runc-1.0.0-2.amzn2.x86_64                                                                                                                             3/5 
  Verifying  : pigz-2.3.4-1.amzn2.0.1.x86_64                                                                                                                         4/5 
  Verifying  : libcgroup-0.41-21.amzn2.x86_64                                                                                                                        5/5 

Installed:
  docker.x86_64 0:20.10.7-5.amzn2                                                                                                                                        

Dependency Installed:
  containerd.x86_64 0:1.4.6-8.amzn2           libcgroup.x86_64 0:0.41-21.amzn2           pigz.x86_64 0:2.3.4-1.amzn2.0.1           runc.x86_64 0:1.0.0-2.amzn2          

Complete!
  0  ansible2                 available    \
        [ =2.4.2  =2.4.6  =2.8  =stable ]
  2  httpd_modules            available    [ =1.0  =stable ]
  3  memcached1.5             available    \
        [ =1.5.1  =1.5.16  =1.5.17 ]
  5  postgresql9.6            available    \
        [ =9.6.6  =9.6.8  =stable ]
  6  postgresql10             available    [ =10  =stable ]
  9  R3.4                     available    [ =3.4.3  =stable ]
 10  rust1                    available    \
        [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0
          =stable ]
 11  vim                      available    [ =8.0  =stable ]
 18  libreoffice              available    \
        [ =5.0.6.2_15  =5.3.6.1  =stable ]
 19  gimp                     available    [ =2.8.22 ]
 20  docker=latest            enabled      \
        [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
 21  mate-desktop1.x          available    \
        [ =1.19.0  =1.20.0  =stable ]
 22  GraphicsMagick1.3        available    \
        [ =1.3.29  =1.3.32  =1.3.34  =stable ]
 23  tomcat8.5                available    \
        [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50
          =stable ]
 24  epel                     available    [ =7.11  =stable ]
 25  testing                  available    [ =1.0  =stable ]
 26  ecs                      available    [ =stable ]
 27  corretto8                available    \
        [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232
          =1.8.0_242  =stable ]
 28  firecracker              available    [ =0.11  =stable ]
 29  golang1.11               available    \
        [ =1.11.3  =1.11.11  =1.11.13  =stable ]
 30  squid4                   available    [ =4  =stable ]
 32  lustre2.10               available    \
        [ =2.10.5  =2.10.8  =stable ]
 33  java-openjdk11           available    [ =11  =stable ]
 34  lynis                    available    [ =stable ]
 35  kernel-ng                available    [ =stable ]
 36  BCC                      available    [ =0.x  =stable ]
 37  mono                     available    [ =5.x  =stable ]
 38  nginx1                   available    [ =stable ]
 39  ruby2.6                  available    [ =2.6  =stable ]
 40  mock                     available    [ =stable ]
 41  postgresql11             available    [ =11  =stable ]
 42  php7.4                   available    [ =stable ]
 43  livepatch                available    [ =stable ]
 44  python3.8                available    [ =stable ]
 45  haproxy2                 available    [ =stable ]
 46  collectd                 available    [ =stable ]
 47  aws-nitro-enclaves-cli   available    [ =stable ]
 48  R4                       available    [ =stable ]
 49  kernel-5.4               available    [ =stable ]
 50  selinux-ng               available    [ =stable ]
 51  php8.0                   available    [ =stable ]
 52  tomcat9                  available    [ =stable ]
 53  unbound1.13              available    [ =stable ]
 54  mariadb10.5              available    [ =stable ]
 55  kernel-5.10              available    [ =stable ]
 56  redis6                   available    [ =stable ]
 57  ruby3.0                  available    [ =stable ]
 58  postgresql12             available    [ =stable ]
 59  postgresql13             available    [ =stable ]
 60  mock2                    available    [ =stable ]
 61  dnsmasq2.85              available    [ =stable ]

[ec2-user@amazonlinux ~]$ sudo service docker start
Redirecting to /bin/systemctl start docker.service
[ec2-user@amazonlinux ~]$ sudo systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
[ec2-user@amazonlinux ~]$ sudo usermod -a -G docker ec2-user

[ec2-user@amazonlinux ~]$ exit
logout

[ec2-user@amazonlinux ~]$ docker info 
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: 84113eef6fc27af1b01b3181f31bbaf708715301
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.14.268-205.500.amzn2.x86_64
 Operating System: Amazon Linux 2
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.828GiB
 Name: amazonlinux.onprem
 ID: MXVZ:LQK7:BVKI:WECH:XNBN:QJUK:IXYU:FADA:4EYI:JOHA:VS3R:LNLX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

[ec2-user@amazonlinux ~]$ docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.7
 Storage Driver: overlay2
  Backing Filesystem: xfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc version: 84113eef6fc27af1b01b3181f31bbaf708715301
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 4.14.268-205.500.amzn2.x86_64
 Operating System: Amazon Linux 2
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.828GiB
 Name: amazonlinux.onprem
 ID: MXVZ:LQK7:BVKI:WECH:XNBN:QJUK:IXYU:FADA:4EYI:JOHA:VS3R:LNLX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

启动minikube

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[ec2-user@amazonlinux ~]$ minikube start
* minikube v1.25.2 on Amazon 2
* Automatically selected the docker driver. Other choices: none, ssh
* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* Downloading Kubernetes v1.23.3 preload ...
    > preloaded-images-k8s-v17-v1...: 505.68 MiB / 505.68 MiB  100.00% 14.20 Mi
    > index.docker.io/kicbase/sta...: 379.06 MiB / 379.06 MiB  100.00% 2.11 MiB
! minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.30, but successfully downloaded docker.io/kicbase/stable:v0.0.30 as a fallback image
* Creating docker container (CPUs=2, Memory=2200MB) ...
! This container is having trouble accessing https://k8s.gcr.io
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
* Preparing Kubernetes v1.23.3 on Docker 20.10.12 ...
  - kubelet.housekeeping-interval=5m
  - Generating certificates and keys ...
  - Booting up control plane ...
  - Configuring RBAC rules ...
* Verifying Kubernetes components...
  - Using image gcr.io/k8s-minikube/storage-provisioner:v5
* Enabled addons: default-storageclass, storage-provisioner
* kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Interact with your cluster

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[ec2-user@amazonlinux ~]$ minikube kubectl -- get pods -A 
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 44.43 MiB / 44.43 MiB [-------------] 100.00% 17.41 MiB p/s 2.8s
NAMESPACE     NAME                               READY   STATUS    RESTARTS       AGE
kube-system   coredns-64897985d-cm6h7            1/1     Running   0              2m3s
kube-system   etcd-minikube                      1/1     Running   0              2m15s
kube-system   kube-apiserver-minikube            1/1     Running   0              2m15s
kube-system   kube-controller-manager-minikube   1/1     Running   0              2m15s
kube-system   kube-proxy-s2sf4                   1/1     Running   0              2m3s
kube-system   kube-scheduler-minikube            1/1     Running   0              2m15s
kube-system   storage-provisioner                1/1     Running   1 (101s ago)   2m14s

[ec2-user@amazonlinux ~]$ alias kubectl="minikube kubectl --"
[ec2-user@amazonlinux ~]$ kubectl get pods -A 
NAMESPACE     NAME                               READY   STATUS    RESTARTS        AGE
kube-system   coredns-64897985d-cm6h7            1/1     Running   0               5m5s
kube-system   etcd-minikube                      1/1     Running   0               5m17s
kube-system   kube-apiserver-minikube            1/1     Running   0               5m17s
kube-system   kube-controller-manager-minikube   1/1     Running   0               5m17s
kube-system   kube-proxy-s2sf4                   1/1     Running   0               5m5s
kube-system   kube-scheduler-minikube            1/1     Running   0               5m17s
kube-system   storage-provisioner                1/1     Running   1 (4m43s ago)   5m16s

# 查看配置
[ec2-user@amazonlinux ~]$ cat .kube/config 
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /home/ec2-user/.minikube/ca.crt
    extensions:
    - extension:
        last-update: Sun, 03 Apr 2022 16:43:46 UTC
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: cluster_info
    server: https://192.168.49.2:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    extensions:
    - extension:
        last-update: Sun, 03 Apr 2022 16:43:46 UTC
        provider: minikube.sigs.k8s.io
        version: v1.25.2
      name: context_info
    namespace: default
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /home/ec2-user/.minikube/profiles/minikube/client.crt
    client-key: /home/ec2-user/.minikube/profiles/minikube/client.key
[ec2-user@amazonlinux ~]$ 

或者做一个软连接的kubectl:

1
2
3
4
5
# https://minikube.sigs.k8s.io/docs/handbook/kubectl/
# https://kubernetes.io/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/
# https://minikube.sigs.k8s.io/docs/handbook/kubectl/

ln -s $(which minikube) /usr/local/bin/kubectl

对系统做了些什么?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[ec2-user@amazonlinux ~]$ docker images 
REPOSITORY       TAG       IMAGE ID       CREATED       SIZE
kicbase/stable   v0.0.30   1312ccd2422d   7 weeks ago   1.14GB
[ec2-user@amazonlinux ~]$ docker ps 
CONTAINER ID   IMAGE                    COMMAND                  CREATED         STATUS         PORTS                                                                                                                                  NAMES
19887e6799fb   kicbase/stable:v0.0.30   "/usr/local/bin/entr…"   7 minutes ago   Up 7 minutes   127.0.0.1:49157->22/tcp, 127.0.0.1:49156->2376/tcp, 127.0.0.1:49155->5000/tcp, 127.0.0.1:49154->8443/tcp, 127.0.0.1:49153->32443/tcp   minikube

# 进到容器内查看
[ec2-user@amazonlinux ~]$ docker exec -ti 19887e6799fb bash 

[ec2-user@amazonlinux ~]$ minikube ssh
docker@minikube:~$ sudo su -
root@minikube:/# 
root@minikube:/# docker ps -a 
CONTAINER ID   IMAGE                  COMMAND                  CREATED         STATUS                     PORTS     NAMES
317a4dc12504   6e38f40d628d           "/storage-provisioner"   7 minutes ago   Up 7 minutes                         k8s_storage-provisioner_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_1
e0876840ef56   a4ca41631cc7           "/coredns -conf /etc…"   7 minutes ago   Up 7 minutes                         k8s_coredns_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_0
485899a5fe0c   9b7cc9982109           "/usr/local/bin/kube…"   7 minutes ago   Up 7 minutes                         k8s_kube-proxy_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_0
0faab30374f5   k8s.gcr.io/pause:3.6   "/pause"                 7 minutes ago   Up 7 minutes                         k8s_POD_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_0
ae99f0b5b873   k8s.gcr.io/pause:3.6   "/pause"                 7 minutes ago   Up 7 minutes                         k8s_POD_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_0
fdeeb06fda78   6e38f40d628d           "/storage-provisioner"   7 minutes ago   Exited (1) 7 minutes ago             k8s_storage-provisioner_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_0
f83e36d2d77e   k8s.gcr.io/pause:3.6   "/pause"                 7 minutes ago   Up 7 minutes                         k8s_POD_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_0
df73834cbaf8   b07520cd7ab7           "kube-controller-man…"   8 minutes ago   Up 8 minutes                         k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_0
49ad661cee86   25f8c7f3da61           "etcd --advertise-cl…"   8 minutes ago   Up 8 minutes                         k8s_etcd_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_0
2c28a97b3875   99a3486be4f2           "kube-scheduler --au…"   8 minutes ago   Up 8 minutes                         k8s_kube-scheduler_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_0
72aca4e710b6   f40be0088a83           "kube-apiserver --ad…"   8 minutes ago   Up 8 minutes                         k8s_kube-apiserver_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_0
97c6ecde381c   k8s.gcr.io/pause:3.6   "/pause"                 8 minutes ago   Up 8 minutes                         k8s_POD_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_0
9140211bc570   k8s.gcr.io/pause:3.6   "/pause"                 8 minutes ago   Up 8 minutes                         k8s_POD_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_0
b27ec09ec789   k8s.gcr.io/pause:3.6   "/pause"                 8 minutes ago   Up 8 minutes                         k8s_POD_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_0
0aef74ead92e   k8s.gcr.io/pause:3.6   "/pause"                 8 minutes ago   Up 8 minutes                         k8s_POD_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_0

root@minikube:/# docker images 
REPOSITORY                                TAG       IMAGE ID       CREATED         SIZE
k8s.gcr.io/kube-apiserver                 v1.23.3   f40be0088a83   2 months ago    135MB
k8s.gcr.io/kube-proxy                     v1.23.3   9b7cc9982109   2 months ago    112MB
k8s.gcr.io/kube-scheduler                 v1.23.3   99a3486be4f2   2 months ago    53.5MB
k8s.gcr.io/kube-controller-manager        v1.23.3   b07520cd7ab7   2 months ago    125MB
k8s.gcr.io/etcd                           3.5.1-0   25f8c7f3da61   5 months ago    293MB
k8s.gcr.io/coredns/coredns                v1.8.6    a4ca41631cc7   5 months ago    46.8MB
k8s.gcr.io/pause                          3.6       6270bb605e12   7 months ago    683kB
kubernetesui/dashboard                    v2.3.1    e1482a24335a   9 months ago    220MB
kubernetesui/metrics-scraper              v1.0.7    7801cfc6d5c0   9 months ago    34.4MB
gcr.io/k8s-minikube/storage-provisioner   v5        6e38f40d628d   12 months ago   31.5MB

更便捷的管理minikube docker:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# https://minikube.sigs.k8s.io/docs/handbook/pushing/#1-pushing-directly-to-the-in-cluster-docker-daemon-docker-env
[ec2-user@amazonlinux ~]$ eval $(minikube docker-env)
# 原理就是设置了环境变量,docker连上了远程服务:export DOCKER_HOST="tcp://192.168.49.2:2376"

[ec2-user@amazonlinux ~]$ docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS     NAMES
344dc0e8c1e6   7801cfc6d5c0           "/metrics-sidecar"       13 minutes ago   Up 13 minutes             k8s_dashboard-metrics-scraper_dashboard-metrics-scraper-58549894f-mzhg2_kubernetes-dashboard_4d6591df-2ee1-46b1-b44c-46ef748a3cd8_0
276a2b6b591f   e1482a24335a           "/dashboard --insecu…"   13 minutes ago   Up 13 minutes             k8s_kubernetes-dashboard_kubernetes-dashboard-ccd587f44-w22lx_kubernetes-dashboard_eb06974d-a4e6-459a-b135-b2426696a75f_0
739f9fdc02bf   k8s.gcr.io/pause:3.6   "/pause"                 13 minutes ago   Up 13 minutes             k8s_POD_dashboard-metrics-scraper-58549894f-mzhg2_kubernetes-dashboard_4d6591df-2ee1-46b1-b44c-46ef748a3cd8_0
9b9d38bdb6d7   k8s.gcr.io/pause:3.6   "/pause"                 13 minutes ago   Up 13 minutes             k8s_POD_kubernetes-dashboard-ccd587f44-w22lx_kubernetes-dashboard_eb06974d-a4e6-459a-b135-b2426696a75f_0
8fd387311710   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_hello-minikube-74c6b47596-gfxrl_default_689891ce-a761-46a6-aa16-fb33dd037c45_0
317a4dc12504   6e38f40d628d           "/storage-provisioner"   8 hours ago      Up 8 hours                k8s_storage-provisioner_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_1
e0876840ef56   a4ca41631cc7           "/coredns -conf /etc…"   8 hours ago      Up 8 hours                k8s_coredns_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_0
485899a5fe0c   9b7cc9982109           "/usr/local/bin/kube…"   8 hours ago      Up 8 hours                k8s_kube-proxy_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_0
0faab30374f5   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_0
ae99f0b5b873   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_0
f83e36d2d77e   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_0
df73834cbaf8   b07520cd7ab7           "kube-controller-man…"   8 hours ago      Up 8 hours                k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_0
49ad661cee86   25f8c7f3da61           "etcd --advertise-cl…"   8 hours ago      Up 8 hours                k8s_etcd_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_0
2c28a97b3875   99a3486be4f2           "kube-scheduler --au…"   8 hours ago      Up 8 hours                k8s_kube-scheduler_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_0
72aca4e710b6   f40be0088a83           "kube-apiserver --ad…"   8 hours ago      Up 8 hours                k8s_kube-apiserver_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_0
97c6ecde381c   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_0
9140211bc570   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_0
b27ec09ec789   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_0
0aef74ead92e   k8s.gcr.io/pause:3.6   "/pause"                 8 hours ago      Up 8 hours                k8s_POD_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_0

管理:

1
2
3
4
minikube cache add alpine:latest
minikube cache reload
minikube cache list
minikube cache delete <image name>

dashboard

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[ec2-user@amazonlinux ~]$ minikube dashboard
* Enabling dashboard ...
  - Using image kubernetesui/metrics-scraper:v1.0.7
  - Using image kubernetesui/dashboard:v2.3.1
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
* Opening http://127.0.0.1:37163/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
  http://127.0.0.1:37163/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

[ec2-user@amazonlinux ~]$ sudo netstat -anp | grep 37163 | grep LISTEN
tcp        0      0 127.0.0.1:37163         0.0.0.0:*               LISTEN      71016/kubectl       

[ec2-user@amazonlinux ~]$ ps aux|grep 71016
ec2-user   71016  0.0  0.9 750808 38932 pts/2    Sl+  00:59   0:00 /home/ec2-user/.minikube/cache/linux/amd64/v1.23.3/kubectl --cluster minikube --context minikube proxy --port 0


# 再获取访问地址
[ec2-user@amazonlinux ~]$ minikube dashboard --url
* Verifying dashboard health ...
* Launching proxy ...
* Verifying proxy health ...
http://127.0.0.1:43247/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

hello world

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
[ec2-user@amazonlinux ~]$ eval $(minikube docker-env)
[ec2-user@amazonlinux ~]$ docker load -i echoserver.tar.gz 
6cc9890d69b6: Loading layer [==================================================>]  61.68MB/61.68MB
5f70bf18a086: Loading layer [==================================================>]  1.024kB/1.024kB
e105cd217163: Loading layer [==================================================>]  8.704kB/8.704kB
9f9b8efa9a34: Loading layer [==================================================>]  83.34MB/83.34MB
4cc84b7b3aba: Loading layer [==================================================>]  3.072kB/3.072kB
e2615e4925e2: Loading layer [==================================================>]  3.072kB/3.072kB
1787713d6d5d: Loading layer [==================================================>]   5.12kB/5.12kB
67639a8a7916: Loading layer [==================================================>]  2.048kB/2.048kB
Loaded image: k8s.gcr.io/echoserver:1.4

[ec2-user@amazonlinux ~]$ docker images 
REPOSITORY                                TAG       IMAGE ID       CREATED         SIZE
k8s.gcr.io/kube-apiserver                 v1.23.3   f40be0088a83   2 months ago    135MB
k8s.gcr.io/kube-scheduler                 v1.23.3   99a3486be4f2   2 months ago    53.5MB
k8s.gcr.io/kube-proxy                     v1.23.3   9b7cc9982109   2 months ago    112MB
k8s.gcr.io/kube-controller-manager        v1.23.3   b07520cd7ab7   2 months ago    125MB
k8s.gcr.io/etcd                           3.5.1-0   25f8c7f3da61   5 months ago    293MB
k8s.gcr.io/coredns/coredns                v1.8.6    a4ca41631cc7   6 months ago    46.8MB
k8s.gcr.io/pause                          3.6       6270bb605e12   7 months ago    683kB
kubernetesui/dashboard                    v2.3.1    e1482a24335a   10 months ago   220MB
kubernetesui/metrics-scraper              v1.0.7    7801cfc6d5c0   10 months ago   34.4MB
gcr.io/k8s-minikube/storage-provisioner   v5        6e38f40d628d   12 months ago   31.5MB
k8s.gcr.io/echoserver                     1.4       a90209bb39e3   5 years ago     140MB


# kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
# kubectl expose deployment hello-minikube --type=NodePort --port=8080

# kubectl --help

[ec2-user@amazonlinux ~]$ kubectl get svc 
NAME             TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort    10.98.195.3   <none>        8080:32754/TCP   7h
kubernetes       ClusterIP   10.96.0.1     <none>        443/TCP          12d

[ec2-user@amazonlinux ~]$ kubectl get services hello-minikube
NAME             TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
hello-minikube   NodePort   10.98.195.3   <none>        8080:32754/TCP   7h59m


# kubectl port-forward service/hello-minikube 7080:8080

[ec2-user@amazonlinux ~]$ kubectl port-forward --address 0.0.0.0 service/hello-minikube 7080:8080
Forwarding from 0.0.0.0:7080 -> 8080
Handling connection for 7080
Handling connection for 7080

浏览器访问 http://192.168.191.133:7080/

load balancer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[ec2-user@amazonlinux ~]$ kubectl create deployment balanced --image=k8s.gcr.io/echoserver:1.4  
deployment.apps/balanced created
[ec2-user@amazonlinux ~]$ kubectl expose deployment balanced --type=LoadBalancer --port=8080
service/balanced exposed
[ec2-user@amazonlinux ~]$ minikube tunnel


[ec2-user@amazonlinux ~]$ kubectl get services balanced
NAME       TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)          AGE
balanced   LoadBalancer   10.100.193.49   10.100.193.49   8080:30406/TCP   13s
[ec2-user@amazonlinux ~]$ curl 10.100.193.49:8080
CLIENT VALUES:
client_address=172.17.0.1
command=GET
real path=/
query=nil
request_version=1.1
request_uri=http://10.100.193.49:8080/

SERVER VALUES:
server_version=nginx: 1.10.0 - lua: 10001

HEADERS RECEIVED:
accept=*/*
host=10.100.193.49:8080
user-agent=curl/7.79.1
BODY:
[ec2-user@amazonlinux ~]$ 

清理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
[ec2-user@amazonlinux ~]$ minikube pause
* Pausing node minikube ... 
* Paused 18 containers in: kube-system, kubernetes-dashboard, storage-gluster, istio-operator
[ec2-user@amazonlinux ~]$ minikube unpause
* Unpausing node minikube ... 
* Unpaused 18 containers in: kube-system, kubernetes-dashboard, storage-gluster, istio-operator

###!!!!
[ec2-user@amazonlinux ~]$ minikube config set memory 16384
! These changes will take effect upon a minikube delete and then a minikube start

[ec2-user@amazonlinux ~]$ minikube config unset memory


[ec2-user@amazonlinux ~]$ docker ps 
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS     NAMES
01cf3a66eb7c   a90209bb39e3           "nginx -g 'daemon of…"   6 minutes ago    Up 6 minutes              k8s_echoserver_balanced-5b98d98bf8-t464f_default_c6b70ff1-d799-4633-bf13-e481052a5da1_0
6a23b4b82131   k8s.gcr.io/pause:3.6   "/pause"                 6 minutes ago    Up 6 minutes              k8s_POD_balanced-5b98d98bf8-t464f_default_c6b70ff1-d799-4633-bf13-e481052a5da1_0
b5817aab4b25   a90209bb39e3           "nginx -g 'daemon of…"   17 minutes ago   Up 17 minutes             k8s_echoserver_hello-minikube-7bc9d7884c-m4r4s_default_cef90979-1c63-4497-acb0-d13847c5a60b_0
9d5677d088c6   k8s.gcr.io/pause:3.6   "/pause"                 17 minutes ago   Up 17 minutes             k8s_POD_hello-minikube-7bc9d7884c-m4r4s_default_cef90979-1c63-4497-acb0-d13847c5a60b_0
c13da70206de   e1482a24335a           "/dashboard --insecu…"   50 minutes ago   Up 50 minutes             k8s_kubernetes-dashboard_kubernetes-dashboard-ccd587f44-w22lx_kubernetes-dashboard_eb06974d-a4e6-459a-b135-b2426696a75f_4
0cead3ead613   6e38f40d628d           "/storage-provisioner"   50 minutes ago   Up 50 minutes             k8s_storage-provisioner_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_5
3a1c19a7a51f   7801cfc6d5c0           "/metrics-sidecar"       51 minutes ago   Up 51 minutes             k8s_dashboard-metrics-scraper_dashboard-metrics-scraper-58549894f-mzhg2_kubernetes-dashboard_4d6591df-2ee1-46b1-b44c-46ef748a3cd8_2
0c48d4f778de   a4ca41631cc7           "/coredns -conf /etc…"   51 minutes ago   Up 51 minutes             k8s_coredns_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_2
ac2ee5d973c6   9b7cc9982109           "/usr/local/bin/kube…"   51 minutes ago   Up 51 minutes             k8s_kube-proxy_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_2
dc17216220bb   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_kubernetes-dashboard-ccd587f44-w22lx_kubernetes-dashboard_eb06974d-a4e6-459a-b135-b2426696a75f_2
9d7f883afb88   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_storage-provisioner_kube-system_c4ea2d31-2c3e-4672-9479-719b0082ac5c_2
d28d9a0a91b1   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_coredns-64897985d-cm6h7_kube-system_0bbdb9ae-d64a-4d74-8b38-ba5bd66af499_2
7e7a16e16d03   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_kube-proxy-s2sf4_kube-system_2e24cec7-d9b3-430e-8869-b9af785588de_2
ace45942773c   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_dashboard-metrics-scraper-58549894f-mzhg2_kubernetes-dashboard_4d6591df-2ee1-46b1-b44c-46ef748a3cd8_2
8f00f611d713   f40be0088a83           "kube-apiserver --ad…"   51 minutes ago   Up 51 minutes             k8s_kube-apiserver_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_2
79f528bbd4d1   99a3486be4f2           "kube-scheduler --au…"   51 minutes ago   Up 51 minutes             k8s_kube-scheduler_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_2
75ce75e37ceb   b07520cd7ab7           "kube-controller-man…"   51 minutes ago   Up 51 minutes             k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_2
50c302912f4a   25f8c7f3da61           "etcd --advertise-cl…"   51 minutes ago   Up 51 minutes             k8s_etcd_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_2
0b1c094b5824   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_kube-controller-manager-minikube_kube-system_b965983ec05322d0973594a01d5e8245_2
7b6d52353935   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_kube-scheduler-minikube_kube-system_be132fe5c6572cb34d93f5e05ce2a540_2
64ba4b4c1a84   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_etcd-minikube_kube-system_9d3d310935e5fabe942511eec3e2cd0c_2
92f05324a447   k8s.gcr.io/pause:3.6   "/pause"                 51 minutes ago   Up 51 minutes             k8s_POD_kube-apiserver-minikube_kube-system_cd6e47233d36a9715b0ab9632f871843_2


[ec2-user@amazonlinux ~]$ minikube addons list
|-----------------------------|----------|--------------|--------------------------------|
|         ADDON NAME          | PROFILE  |    STATUS    |           MAINTAINER           |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador                  | minikube | disabled     | third-party (ambassador)       |
| auto-pause                  | minikube | disabled     | google                         |
| csi-hostpath-driver         | minikube | disabled     | kubernetes                     |
| dashboard                   | minikube | enabled ✅   | kubernetes                     |
| default-storageclass        | minikube | enabled ✅   | kubernetes                     |
| efk                         | minikube | disabled     | third-party (elastic)          |
| freshpod                    | minikube | disabled     | google                         |
| gcp-auth                    | minikube | disabled     | google                         |
| gvisor                      | minikube | disabled     | google                         |
| helm-tiller                 | minikube | disabled     | third-party (helm)             |
| ingress                     | minikube | disabled     | unknown (third-party)          |
| ingress-dns                 | minikube | disabled     | google                         |
| istio                       | minikube | disabled     | third-party (istio)            |
| istio-provisioner           | minikube | disabled     | third-party (istio)            |
| kong                        | minikube | disabled     | third-party (Kong HQ)          |
| kubevirt                    | minikube | disabled     | third-party (kubevirt)         |
| logviewer                   | minikube | disabled     | unknown (third-party)          |
| metallb                     | minikube | disabled     | third-party (metallb)          |
| metrics-server              | minikube | disabled     | kubernetes                     |
| nvidia-driver-installer     | minikube | disabled     | google                         |
| nvidia-gpu-device-plugin    | minikube | disabled     | third-party (nvidia)           |
| olm                         | minikube | disabled     | third-party (operator          |
|                             |          |              | framework)                     |
| pod-security-policy         | minikube | disabled     | unknown (third-party)          |
| portainer                   | minikube | disabled     | portainer.io                   |
| registry                    | minikube | disabled     | google                         |
| registry-aliases            | minikube | disabled     | unknown (third-party)          |
| registry-creds              | minikube | disabled     | third-party (upmc enterprises) |
| storage-provisioner         | minikube | enabled ✅   | google                         |
| storage-provisioner-gluster | minikube | disabled     | unknown (third-party)          |
| volumesnapshots             | minikube | disabled     | kubernetes                     |
|-----------------------------|----------|--------------|--------------------------------|

[ec2-user@amazonlinux ~]$ minikube delete --all
* Deleting "minikube" in docker ...
* Removing /home/ec2-user/.minikube/machines/minikube ...
* Removed all traces of the "minikube" cluster.
* Successfully deleted all profiles


#Create a second cluster running an older Kubernetes release:
# minikube start -p aged --kubernetes-version=v1.16.1

k3d

  • https://k3d.io/v5.4.1/ k3d is a lightweight wrapper to run k3s (Rancher Lab’s minimal Kubernetes distribution) in docker.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
[ec2-user@amazonlinux ~]$ wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
Preparing to install k3d into /usr/local/bin
k3d installed into /usr/local/bin/k3d
Run 'k3d --help' to see what you can do with it.

[ec2-user@amazonlinux ~]$ k3d cluster create mycluster
INFO[0000] Prep: Network                                
INFO[0000] Created network 'k3d-mycluster'              
INFO[0000] Created image volume k3d-mycluster-images    
INFO[0000] Starting new tools node...                   
INFO[0001] Creating node 'k3d-mycluster-server-0'       
INFO[0003] Pulling image 'ghcr.io/k3d-io/k3d-tools:5.4.1' 
INFO[0007] Pulling image 'docker.io/rancher/k3s:v1.22.7-k3s1' 
INFO[0009] Starting Node 'k3d-mycluster-tools'          
INFO[0084] Creating LoadBalancer 'k3d-mycluster-serverlb' 
INFO[0087] Pulling image 'ghcr.io/k3d-io/k3d-proxy:5.4.1' 
INFO[0098] Using the k3d-tools node to gather environment information 
INFO[0098] HostIP: using network gateway 172.18.0.1 address 
INFO[0098] Starting cluster 'mycluster'                 
INFO[0098] Starting servers...                          
INFO[0098] Starting Node 'k3d-mycluster-server-0'       
INFO[0104] All agents already running.                  
INFO[0104] Starting helpers...                          
INFO[0104] Starting Node 'k3d-mycluster-serverlb'       
INFO[0111] Injecting records for hostAliases (incl. host.k3d.internal) and for 2 network members into CoreDNS configmap... 
INFO[0114] Cluster 'mycluster' created successfully!    
INFO[0114] You can now use it like this:                
kubectl cluster-info

[ec2-user@amazonlinux ~]$ docker ps 
CONTAINER ID   IMAGE                            COMMAND                  CREATED         STATUS         PORTS                             NAMES
5d57c1328e66   ghcr.io/k3d-io/k3d-proxy:5.4.1   "/bin/sh -c nginx-pr…"   6 minutes ago   Up 6 minutes   80/tcp, 0.0.0.0:41489->6443/tcp   k3d-mycluster-serverlb
add7ac133348   rancher/k3s:v1.22.7-k3s1         "/bin/k3s server --t…"   6 minutes ago   Up 6 minutes                                     k3d-mycluster-server-0

# 注意:上面的kubectl是minikue的,需要下载
[ec2-user@amazonlinux ~]$ curl -LO https://dl.k8s.io/release/v1.23.0/bin/linux/amd64/kubectl
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   154  100   154    0     0    230      0 --:--:-- --:--:-- --:--:--   230
100 44.4M  100 44.4M    0     0  1989k      0  0:00:22  0:00:22 --:--:-- 2256k
[ec2-user@amazonlinux ~]$ ll
[ec2-user@amazonlinux ~]$ sudo cp kubectl /usr/local/bin/
[ec2-user@amazonlinux ~]$ which kubectl
/usr/local/bin/kubectl

[ec2-user@amazonlinux ~]$ kubectl get nodes
NAME                     STATUS   ROLES                  AGE   VERSION
k3d-mycluster-server-0   Ready    control-plane,master   47m   v1.22.7+k3s1

[ec2-user@amazonlinux ~]$ kubectl get pods -A 
NAMESPACE     NAME                                      READY   STATUS      RESTARTS      AGE
kube-system   local-path-provisioner-84bb864455-s8t7f   1/1     Running     0             45m
kube-system   coredns-96cc4f57d-vvmrx                   1/1     Running     0             45m
kube-system   helm-install-traefik-crd--1-ghv9f         0/1     Completed   0             45m
kube-system   helm-install-traefik--1-s4ktb             0/1     Completed   1             45m
kube-system   svclb-traefik-9jt5d                       2/2     Running     1 (44m ago)   44m
kube-system   metrics-server-ff9dbcb6c-72mwc            1/1     Running     0             45m
kube-system   traefik-56c4b88c4b-f454f                  1/1     Running     0             44m
[ec2-user@amazonlinux ~]$ 

[ec2-user@amazonlinux ~]$ k3d cluster list 
NAME        SERVERS   AGENTS   LOADBALANCER
mycluster   1/1       0/0      true
[ec2-user@amazonlinux ~]$ k3d node create worker1 --cluster mycluster
INFO[0000] Adding 1 node(s) to the runtime local cluster 'mycluster'... 
INFO[0000] Using the k3d-tools node to gather environment information 
INFO[0000] Starting new tools node...                   
INFO[0000] Starting Node 'k3d-mycluster-tools'          
INFO[0001] HostIP: using network gateway 172.18.0.1 address 
INFO[0001] Starting Node 'k3d-worker1-0'                
INFO[0009] Successfully created 1 node(s)!              
[ec2-user@amazonlinux ~]$ kubectl get nodes
NAME                     STATUS     ROLES                  AGE   VERSION
k3d-mycluster-server-0   Ready      control-plane,master   50m   v1.22.7+k3s1
k3d-worker1-0            NotReady   <none>                 7s    v1.22.7+k3s1
[ec2-user@amazonlinux ~]$ 

[ec2-user@amazonlinux ~]$ kubectl get nodes                          
NAME                     STATUS   ROLES                  AGE   VERSION
k3d-mycluster-server-0   Ready    control-plane,master   50m   v1.22.7+k3s1
k3d-worker1-0            Ready    <none>                 24s   v1.22.7+k3s1
[ec2-user@amazonlinux ~]$ 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[ec2-user@amazonlinux ~]$ cat .vimrc 
set paste

[ec2-user@amazonlinux ~]$ cat thatfile.yaml 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80

[ec2-user@amazonlinux ~]$ export KUBECONFIG="$(k3d kubeconfig write mycluster)"  
[ec2-user@amazonlinux ~]$ kubectl create deployment nginx --image=nginx
deployment.apps/nginx created
[ec2-user@amazonlinux ~]$ kubectl create service clusterip nginx --tcp=80:80
service/nginx created

[ec2-user@amazonlinux ~]$ kubectl apply -f thatfile.yaml
ingress.networking.k8s.io/nginx created

查看结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[ec2-user@amazonlinux ~]$ kubectl get all -A -o wide
NAMESPACE     NAME                                          READY   STATUS      RESTARTS      AGE     IP          NODE                     NOMINATED NODE   READINESS GATES
kube-system   pod/local-path-provisioner-84bb864455-s8t7f   1/1     Running     0             64m     10.42.0.5   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/coredns-96cc4f57d-vvmrx                   1/1     Running     0             64m     10.42.0.6   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/helm-install-traefik-crd--1-ghv9f         0/1     Completed   0             64m     10.42.0.4   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/helm-install-traefik--1-s4ktb             0/1     Completed   1             64m     10.42.0.3   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/svclb-traefik-9jt5d                       2/2     Running     1 (63m ago)   63m     10.42.0.7   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/metrics-server-ff9dbcb6c-72mwc            1/1     Running     0             64m     10.42.0.2   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/traefik-56c4b88c4b-f454f                  1/1     Running     0             63m     10.42.0.8   k3d-mycluster-server-0   <none>           <none>
kube-system   pod/svclb-traefik-dvvrp                       2/2     Running     1 (13m ago)   14m     10.42.1.2   k3d-worker1-0            <none>           <none>
default       pod/nginx-6799fc88d8-vgc9x                    1/1     Running     0             4m34s   10.42.1.3   k3d-worker1-0            <none>           <none>

NAMESPACE     NAME                     TYPE           CLUSTER-IP      EXTERNAL-IP             PORT(S)                      AGE     SELECTOR
default       service/kubernetes       ClusterIP      10.43.0.1       <none>                  443/TCP                      64m     <none>
kube-system   service/kube-dns         ClusterIP      10.43.0.10      <none>                  53/UDP,53/TCP,9153/TCP       64m     k8s-app=kube-dns
kube-system   service/metrics-server   ClusterIP      10.43.88.129    <none>                  443/TCP                      64m     k8s-app=metrics-server
kube-system   service/traefik          LoadBalancer   10.43.4.2       172.18.0.2,172.18.0.4   80:32037/TCP,443:30484/TCP   63m     app.kubernetes.io/instance=traefik,app.kubernetes.io/name=traefik
default       service/nginx            ClusterIP      10.43.206.223   <none>                  80/TCP                       4m30s   app=nginx

NAMESPACE     NAME                           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE   CONTAINERS               IMAGES                                                SELECTOR
kube-system   daemonset.apps/svclb-traefik   2         2         2       2            2           <none>          63m   lb-port-80,lb-port-443   rancher/klipper-lb:v0.3.4,rancher/klipper-lb:v0.3.4   app=svclb-traefik

NAMESPACE     NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS               IMAGES                                   SELECTOR
kube-system   deployment.apps/local-path-provisioner   1/1     1            1           64m     local-path-provisioner   rancher/local-path-provisioner:v0.0.21   app=local-path-provisioner
kube-system   deployment.apps/coredns                  1/1     1            1           64m     coredns                  rancher/mirrored-coredns-coredns:1.8.6   k8s-app=kube-dns
kube-system   deployment.apps/metrics-server           1/1     1            1           64m     metrics-server           rancher/mirrored-metrics-server:v0.5.2   k8s-app=metrics-server
kube-system   deployment.apps/traefik                  1/1     1            1           63m     traefik                  rancher/mirrored-library-traefik:2.6.1   app.kubernetes.io/instance=traefik,app.kubernetes.io/name=traefik
default       deployment.apps/nginx                    1/1     1            1           4m34s   nginx                    nginx                                    app=nginx

NAMESPACE     NAME                                                DESIRED   CURRENT   READY   AGE     CONTAINERS               IMAGES                                   SELECTOR
kube-system   replicaset.apps/local-path-provisioner-84bb864455   1         1         1       64m     local-path-provisioner   rancher/local-path-provisioner:v0.0.21   app=local-path-provisioner,pod-template-hash=84bb864455
kube-system   replicaset.apps/coredns-96cc4f57d                   1         1         1       64m     coredns                  rancher/mirrored-coredns-coredns:1.8.6   k8s-app=kube-dns,pod-template-hash=96cc4f57d
kube-system   replicaset.apps/metrics-server-ff9dbcb6c            1         1         1       64m     metrics-server           rancher/mirrored-metrics-server:v0.5.2   k8s-app=metrics-server,pod-template-hash=ff9dbcb6c
kube-system   replicaset.apps/traefik-56c4b88c4b                  1         1         1       63m     traefik                  rancher/mirrored-library-traefik:2.6.1   app.kubernetes.io/instance=traefik,app.kubernetes.io/name=traefik,pod-template-hash=56c4b88c4b
default       replicaset.apps/nginx-6799fc88d8                    1         1         1       4m34s   nginx                    nginx                                    app=nginx,pod-template-hash=6799fc88d8

NAMESPACE     NAME                                 COMPLETIONS   DURATION   AGE   CONTAINERS   IMAGES                                      SELECTOR
kube-system   job.batch/helm-install-traefik-crd   1/1           52s        64m   helm         rancher/klipper-helm:v0.6.6-build20211022   controller-uid=1d4ac20d-0436-4d54-9d8b-e37fe7c46e6e
kube-system   job.batch/helm-install-traefik       1/1           53s        64m   helm         rancher/klipper-helm:v0.6.6-build20211022   controller-uid=b51475a5-3fac-4b96-b218-7dd7a094512b

[ec2-user@amazonlinux ~]$ kubectl get ingress 
NAME    CLASS    HOSTS   ADDRESS                 PORTS   AGE
nginx   <none>   *       172.18.0.2,172.18.0.4   80      3m18s

[ec2-user@amazonlinux ~]$ curl 172.18.0.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[ec2-user@amazonlinux ~]$ 

–END

Comments