k8s svc负载均衡
- run创建deploy
[root@zjucst-52668 ~]# kubectl run http --image=katacoda/docker-http-server:latest --replicas=1 -n cka
- 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
- 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>
- 访问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 ~]#
继续阅读与本文标签相同的文章
下一篇 :
阿里的攻城狮和程序媛用算法给骗子“画个像”
-
MySQL每组求最值的记录与每组前N条记录
2026-05-18栏目: 教程
-
OCP-052考试题库汇总(55)-CUUG内部解答版
2026-05-18栏目: 教程
-
【云栖活动】架构师、产品经理一对一座谈会/WORKSHOP-已截止
2026-05-18栏目: 教程
-
MySQL入门书籍和方法分享
2026-05-18栏目: 教程
-
树莓派4&阿里云物联网平台上云开发实操
2026-05-18栏目: 教程
