当前位置:   article > 正文

k8s svc负载均衡

svc负载均衡

k8s svc负载均衡

  • run创建deploy
[root@zjucst-52668 ~]#   kubectl run http --image=katacoda/docker-http-server:latest --replicas=1 -n cka

  • 1
  • 2
  • expose创建svc,暴露ip端口,并且为其配置虚拟网卡
[root@zjucst-52668 ~]#   274  kubectl expose deployment http --external-ip="172.17.0.1" --port=8000 --target-port=80 -n cka
[root@zjucst-52668 ~]#   ifconfig eth0:cka 172.17.0.1 up
  • 1
  • 2
  • scale水平扩容pods
[root@zjucst-52668 ~]#    kubectl scale deployment http --replicas=3 -ncka
[root@zjucst-52668 ~]# kubectl get pods -n cka
NAME                   READY     STATUS    RESTARTS   AGE
http-989f8bcf9-gvjdf   1/1       Running   0          11s
http-989f8bcf9-jk556   1/1       Running   0          32m
http-989f8bcf9-p66hp   1/1       Running   0          11s
[root@zjucst-52668 ~]# 
[root@zjucst-52668 ~]# kubectl describe svc http -ncka
Name:              http
Namespace:         cka
Labels:            run=http
Annotations:       <none>
Selector:          run=http
Type:              ClusterIP
IP:                10.247.204.130
External IPs:      172.17.0.1
Port:              <unset>  8000/TCP
TargetPort:        80/TCP
Endpoints:         172.16.0.43:80,172.16.0.44:80,172.16.0.45:80
Session Affinity:  None
Events:            <none>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 访问svc ip:port,将会随机得到不同pod的相应
[root@zjucst-52668 ~]# kubectl get svc -ncka
NAME      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
http      ClusterIP   10.247.204.130   172.17.0.1    8000/TCP   22m
[root@zjucst-52668 ~]# kubectl describe svc http -ncka
Name:              http
Namespace:         cka
Labels:            run=http
Annotations:       <none>
Selector:          run=http
Type:              ClusterIP
IP:                10.247.204.130
External IPs:      172.17.0.1
Port:              <unset>  8000/TCP
TargetPort:        80/TCP
Endpoints:         172.16.0.43:80,172.16.0.44:80,172.16.0.45:80
Session Affinity:  None
Events:            <none>
[root@zjucst-52668 ~]# 
[root@zjucst-52668 ~]# curl 172.17.0.1:8000
<h1>This request was processed by host: http-989f8bcf9-gvjdf</h1>
[root@zjucst-52668 ~]# curl 172.17.0.1:8000
<h1>This request was processed by host: http-989f8bcf9-p66hp</h1>
[root@zjucst-52668 ~]# curl 172.17.0.1:8000
<h1>This request was processed by host: http-989f8bcf9-jk556</h1>
[root@zjucst-52668 ~]# 


  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/189782
推荐阅读
相关标签
  

闽ICP备14008679号