所以,这几天我一直在尝试在 AWS EKS 上创建一个集群。我设法在 ECR 上上传了 docker 映像,创建了适当的 VPC,但无法从 http://<ip:port 连接它。我正在使用 NodePort 服务来公开项目。该项目是一个返回 JSON 的基本 .NET Core REST API。我正在使用 AWS CLI 和 kubectl 进行操作。我已经在工作节点(EC2 实例)安全协议的入站规则中实现了生成的 nodePort IP。这是我的 yaml 文件;
Cluster.yaml -> 用于使用预先创建的 VPC 设置和定义节点组的 yaml 文件
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: EKS-Demo-Cluster
region: eu-central-1
vpc:
id: vpc-056dbccebc402e9a8
cidr: "192.168.0.0/16"
subnets:
public:
eu-central-1a:
id: subnet-04192a691f3c156a6
eu-central-1b:
id: subnet-0f89762f3d78ccb47
private:
eu-central-1a:
id: subnet-07fe8b089287a16c4
eu-central-1b:
id: subnet-0ae524ea2c78b49a7
nodeGroups:
- name: EKS-public-workers
instanceType: t3.medium
desiredCapacity: 2
- name: EKS-private-workers
instanceType: t3.medium
desiredCapacity: 1
privateNetworking: true
部署.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: sample-app
spec:
replicas: 2
selector:
matchLabels:
app: demojsonapp
template:
metadata:
labels:
app: demojsonapp
spec:
containers:
- name: back-end
image: 921915718885.dkr.ecr.eu-central-1.amazonaws.com/sample_repo:latest
ports:
- name: http
containerPort: 8080
服务.yaml
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: NodePort
selector:
app: demojsonapp
ports:
- protocol: TCP
port: 80
targetPort: 80
我不明白问题出在哪里。如果您能帮助我,我们将不胜感激。
最后,这里是创建镜像的 docker 文件,我上传到 ECR for EKS 集群;
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 3000
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WebApplication2/WebApplication2.csproj", "WebApplication2/"]
RUN dotnet restore "WebApplication2/WebApplication2.csproj"
COPY . .
WORKDIR "/src/WebApplication2"
RUN dotnet build "WebApplication2.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "WebApplication2.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]