Know Your Wisdom

本地搭建 minikube

2022-04-09

Terminology

  • node / worker / worker node: all representing the concrete physical machine.
  • pods: The carrier of multiple docker container, the minimum unit of k8s

Run a simple Nginx Instance

  1. create and run a pod: k run kubia --image=luksa/kubia --port=8080 run/v1
  2. check pod status: k get pods
  1. check the pod description: k describe pod kubia
  2. check logs: k logs kubia

Find out this image seems only support amd64 arch...

Fine, let's change a example, start a nginx:

# delete previous bad pod
k delete pod kubia

# run a new nginx pod
k run ng --image=nginx --port=8080

# check the pod status
k get pods

pretty nice, let's visit it: http://raspberrypi.local:8080/

Oops, it seems can not establish the TCP connection. But Why?

每个 pod 都有自己的 IP 地址,和树莓派的 IP 地址是完全分开的,当在浏览器输入 http://raspberrypi:8080 的时候,其实访问的是树莓派的 host ip 地址,而树莓派 ip 上什么都没有,那肯定就拒绝访问了。

如何才能访问到 pod 中的服务呢?很简单,类似 docker 一样将端口映射到对应的主机端口就可以了。这里会引出几个问题,暂时不作答:

  • 具体如何进行端口映射?
  • docker bridge 网络中的虚拟网卡如何作为交换机工作的?
  • 既然 bridge 有自己的 IP / MAC 地址,为什么不能在 LAN 下直接输入 bridge IP 访问?
  • 假设在我家电脑上访问树莓派 pod 中的 nginx,数据包具体是怎么流转的?

k expose pod ng --type=LoadBalancer --name ng-http

Then: k get services