Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 如何在Amazon AWS上使用NodePort部署Kubernetes服务?_Amazon Web Services_Kubernetes_Cloud - Fatal编程技术网

Amazon web services 如何在Amazon AWS上使用NodePort部署Kubernetes服务?

Amazon web services 如何在Amazon AWS上使用NodePort部署Kubernetes服务?,amazon-web-services,kubernetes,cloud,Amazon Web Services,Kubernetes,Cloud,我使用kops在AWS EC2上创建了一个集群,由一个主节点和两个工作节点组成,所有节点都分配了公共IPv4 现在,我想创建一个部署,其中包含一个使用NodePort向公众公开应用程序的服务 创建服务后,我检索以下信息,显示它正确标识了我的三个吊舱: nlykkei:~/projects/k8s-examples$ kubectl describe svc hello-svc Name: hello-svc Namespace:

我使用
kops
在AWS EC2上创建了一个集群,由一个主节点和两个工作节点组成,所有节点都分配了公共IPv4

现在,我想创建一个部署,其中包含一个使用NodePort向公众公开应用程序的服务

创建服务后,我检索以下信息,显示它正确标识了我的三个吊舱:

nlykkei:~/projects/k8s-examples$ kubectl describe svc hello-svc
Name:                     hello-svc
Namespace:                default
Labels:                   app=hello
Annotations:              kubectl.kubernetes.io/last-applied-configuration:
                            {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"hello"},"name":"hello-svc","namespace":"default"},"spec"...
Selector:                 app=hello-world
Type:                     NodePort
IP:                       100.69.62.27
Port:                     <unset>  8080/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30001/TCP
Endpoints:                100.96.1.5:8080,100.96.2.3:8080,100.96.2.4:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
我已经研究过了,认为NodePort应该满足我的需要吗


感谢您的帮助

所以您希望有一个可以从公共站点访问的服务。为了实现这一点,我建议创建ClusterIP服务,然后为该服务创建入口。因此,假设部署hello world服务于8081,那么您将拥有以下两个对象:

服务:

apiVersion: v1
kind: Service
metadata:
  name: hello-world
labels:
  app: hello-world
spec:
  ports:
  - name: service
    port: 8081(or whatever you want)
    protocol: TCP
    targetPort: 8080 (here goes the opened port in your pods)
  selector:
    app: hello-world
  type: ClusterIP
入口:

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  labels:
    app: hello-world
  name: hello-world
spec:
  rules:
  - host: hello-world.mycutedomainname.com
    http:
      paths:
      - backend:
          serviceName: hello-world
          servicePort: 8081 (or whatever you have set for the service port)
        path: /

注意:服务端口中的名称标签是可选的。

您可以通过部署pod的节点的公共ip进行尝试吗?服务端口从8080更改为80为什么我要将端口更改为80?将targetPort更改为80@Elias-你为什么要我改变?
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  labels:
    app: hello-world
  name: hello-world
spec:
  rules:
  - host: hello-world.mycutedomainname.com
    http:
      paths:
      - backend:
          serviceName: hello-world
          servicePort: 8081 (or whatever you have set for the service port)
        path: /