我在AWS中使用kubeadm
构建了一个单节点Kubernetes“集群”。
我已经使用此配置部署了一个简单的Nginx部署:
kind: Deployment
apiVersion: apps/v1
metadata:
name: nginx0-deployment
labels:
app: nginx0-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx0
template:
metadata:
labels:
app: nginx0
spec:
containers:
- name: nginx
image: k8s.gcr.io/nginx:latest
ports:
- containerPort: 80
name: backend-http
我还创建了一个AWS ELB LoadBalancer:
kind: Service
apiVersion: v1
metadata:
name: nginx0-service
balancing-enabled: "true"
spec:
selector:
app: nginx0-deployment
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
这将创建ELB并打开K8s实例安全组中的相关端口。
{ec2-instance} ~ $ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx0-deployment-548f99f47c-ns75w 1/1 Running 0 3m45s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
service/nginx0-service LoadBalancer 10.106.179.191 acfc4150....elb.amazonaws.com 80:30675/TCP 63s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx0-deployment 1/1 1 1 3m45s
NAME DESIRED CURRENT READY AGE
replicaset.apps/nginx0-deployment-548f99f47c 1 1 1 3m45s
但是,由于浏览到http://acfc4150....elb.amazonaws.com/
无效,ELB和POD之间仍然缺少某些内容-Chrome提示ERR_EMPTY_RESPONSE。
我想这与 ELB端口映射 80:30675 / TCP 有关-我检查了实例上的传入流量,并且看到端口< strong> 30675 ,但没有任何结果。好像未建立此端口与POD的端口80之间的映射?
有什么主意我应该添加到清单中以使其起作用?
谢谢!
答案 0 :(得分:3)
您的标签有误;您的部署具有app: nginx0-deployment
,但是您的 Pods 具有app: nginx0
和Service
则不针对Deployment,它们针对Pod
将您的Service
更新为:
spec:
selector:
app: nginx0
代替