kubernetes的service操作实验

Kubernetes官方提供一个交互式的实验环境:

打开上面的网站,进入到在线的实验平台:

如上所示,实际操作kubectl,创建service,并查看ip地址:

$ kubectl get services/kubernetes-bootcamp
NAME                  TYPE       CLUSTER-IP    EXTERNAL-IP   PORT(S)          AGE
kubernetes-bootcamp   NodePort   10.97.9.161   <none>        8080:32580/TCP   10m

从上面可以看到cluster-ip,和8080 <-> 32580的端口映射。下面查看service获得的endpoints:

$ kubectl describe services/kubernetes-bootcamp
...
Endpoints:                172.18.0.2:8080

endpoints就是kubernetes管理的ip地址和端口资源。下面查看node的ip地址:

$ minikube ip
172.17.0.6

pod的ip地址:

$ kubectl get pods
NAME                                   READY   STATUS    RESTARTS   AGE
kubernetes-bootcamp-6bf84cb898-vpn6f   1/1     Running   0          3m53s

查看pod的label:

$ kubectl describe pods/kubernetes-bootcamp-6bf84cb898-vpn6f
...
Node:               minikube/172.17.0.6
...
Labels:             pod-template-hash=6bf84cb898
                    run=kubernetes-bootcamp
...
IP:                 172.18.0.2

service会利用pod的label进行请求的分发和负载平衡,把请求分发到对应label的pods去(具体的网络转发是由kube-proxy控制的)。综上所述,架构图如下:

kube-proxyservicepod的架构关系如下:

上面的图片来自于Kubernetes Cookbook这本书。下面是书中对kube-proxy的说明:

以上是对services的进一步学习的记录。

My Github Page: https://github.com/liweinan

Powered by Jekyll and Theme by solid

If you have any question want to ask or find bugs regarding with my blog posts, please report it here:
https://github.com/liweinan/liweinan.github.io/issues