-
如果内存不足,可以使用软连接
-
常用命令
- kubectl get svc
- minikube service --url nginx
-
创建.net5项目,并勾选docker支持
- dockefile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 80 FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src COPY ["WebApplication1.csproj", "."] RUN dotnet restore "./WebApplication1.csproj" COPY . . WORKDIR "/src/." RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "WebApplication1.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "WebApplication1.dll"]
-
将项目文件上传到minikube服务器上,并进行docker打包
docker build -t dockerdemo .
-
编写k8s.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: web1 labels: k8s-app: web1 spec: replicas: 2 selector: matchLabels: k8s-app: web1 template: metadata: labels: k8s-app: web1 spec: containers: - name: web1 image: dockerdemo imagePullPolicy: Never ports: - containerPort: 80 --- kind: Service apiVersion: v1 metadata: labels: k8s-app: web1 name: web1 spec: type: NodePort ports: - port: 80 targetPort: 80 selector: k8s-app: web1
-
运行pod
- kubectl create -f web-pod.yaml
- kubectl get pod -o wide
参考: