service代理模式及负载均衡
Posted zc1741845455
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了service代理模式及负载均衡相关的知识,希望对你有一定的参考价值。
[[email protected] ~]# vim service.yaml
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
[[email protected] ~]# kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
svc/kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 5d
svc/nginx-service ClusterIP 10.10.10.85 <none> 88/TCP 20h
[[email protected] ~]# kubectl create -f service.yaml
[[email protected] ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.10.10.1 <none> 443/TCP 5d
my-service ClusterIP 10.10.10.212 <none> 80/TCP,443/TCP 24s
nginx-service ClusterIP 10.10.10.85 <none> 88/TCP 20h
查看pod的标签,用标签来识别,并代理到后端的服务上
[[email protected] ~]# kubectl get pod --show-labels -o wide
nginx-pod 1/1 Running 1 17h 172.17.80.4 192.168.30.23 app=nginx
修改我们创建的my-service,把标签改为nginx,然后我们访问我们的my-service分配的clusterIP就能直接代理到后端的Nginx上了
[[email protected] ~]# kubectl edit svc/my-service
访问10.10.10.212:80
[[email protected] ~]# curl 10.10.10.212:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
[[email protected] ~]# curl 10.10.10.212:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
以上是关于service代理模式及负载均衡的主要内容,如果未能解决你的问题,请参考以下文章