.net core部署到k8s
准备dockerfile
dotnet new mvc --name myweb
dotnet publish -c release -o publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
COPY . .
ENTRYPOINT ["dotnet", "myweb.dll"]
docker build -t dockerdemo .
#docker测试
#docker run --name test -d -p 8080:80 dockerdemo
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
部署应用
kubectl create -f /k8s/web-pod.yml
#排查错误
kubectl describe pod web1-64b8479fc6-czpkq
#查看详细日志
kubectl describe -f web-pod.yml
#删除
kubectl delete -f web-pod.yml
kubectl apply -f /k8s/web-pod.yml
#查看映射的端口
kubectl get pod,svc -o wide
http://192.168.114.134:32285/
标签:core,name,kubectl,app,web1,net,k8s,pod
From: https://www.cnblogs.com/xinzhyu/p/17436280.html