在没有负载均衡的情况下,可以通过以下步骤设置Kubernetes Nginx入口:
kubectl create service nodeport nginx --tcp=80:80
Deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
使用以下命令创建Deployment和Service:
kubectl apply -f Deployment.yaml
kubectl apply -f Service.yaml
kubectl get service nginx-service
请注意,这种方式没有负载均衡,因此所有的流量都将导向单个Nginx Pod。如果需要负载均衡,建议使用云厂商提供的负载均衡服务或第三方负载均衡解决方案。
领取专属 10元无门槛券
手把手带您无忧上云