我试图了解如何正确配置kubernetes服务,这将使我具有以下设置:
阅读文档后,我提出了两种解决方案。 想要将特定服务配置为具有多个实例。由于我们的apache服务器具有硬编码的重定向规则(即依赖于特定的端口),因此后端有两种选择:
如果我使用选项#1,则我不能有多个实例,因为hostNetwork不允许使用同一端口。使用选项#2时,我想我可以拥有所需的功能,但是我遇到有关负载均衡器配额的OpenStack错误(可能是内部问题)。我在这里寻求的是关于如何进行此工作的建议,我对LoadBalancer的理解是否正确,并且可以实现此功能。作为记录,这里是我正在使用的Yaml:
kind: Service
apiVersion: v1
metadata:
name: aaa-global-r
spec:
selector:
app: aaa-global-r
type: LoadBalancer
ports:
- name: aaa-global-r
port: 8252
targetPort: 8252
protocol: TCP
- name: aaa-gr-mon
port: 18252
targetPort: 18252
protocol: TCP
这里的要点是我想保留我的端口(因为我们正在使用配置为与这些端口通信的另一个auth层)。而且,我想拥有这个应用程序的多个实例,它们都将在不同容器中的这些端口上运行,并且我想在内部k8s网络上访问它们。
答案 0 :(得分:-1)
通过RepilcaSets处理多个实例
端口由Kubernetes Services自动处理
示例:
运行3个Nginx实例并在单个端口上访问所有实例:
C02W84XMHTD5:test iahmad$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-h5khl 1/1 Running 1 19m
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ kubectl scale deployment nginx --replicas=3
deployment.extensions/nginx scaled
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-h5khl 1/1 Running 1 19m
nginx-65899c769f-m2pkp 0/1 ContainerCreating 0 5s
nginx-65899c769f-mwlqn 0/1 ContainerCreating 0 5s
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-h5khl 1/1 Running 1 20m
nginx-65899c769f-m2pkp 0/1 ContainerCreating 0 13s
nginx-65899c769f-mwlqn 0/1 ContainerCreating 0 13s
C02W84XMHTD5:test iahmad$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-h5khl 1/1 Running 1 20m
nginx-65899c769f-m2pkp 0/1 ContainerCreating 0 15s
nginx-65899c769f-mwlqn 1/1 Running 0 15s
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-65899c769f-h5khl 1/1 Running 1 20m
nginx-65899c769f-m2pkp 1/1 Running 0 22s
nginx-65899c769f-mwlqn 1/1 Running 0 22s
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 30d
nginx NodePort 10.107.66.154 <none> 80:32622/TCP 18m
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$
C02W84XMHTD5:test iahmad$ curl 192.168.99.105:32622
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>