单机部署 k8s 需要安装 minikube,前往 github release 下载
macos:
brew install minikube
初始化k8s环境
minikube start
安装vscode插件:
示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nest-api-blog
namespace: default
labels:
app: nest-api-blog
spec:
selector:
matchLabels:
app: nest-api-blog
replicas: 1
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: nest-api-blog
spec:
containers:
- name: nest-api-blog
image: saber2pr/next-ssr-blog:v1.6.2
resources:
requests:
cpu: 100m
memory: 100Mi
limits:
cpu: 100m
memory: 100Mi
livenessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 5
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 5
timeoutSeconds: 2
successThreshold: 1
failureThreshold: 3
periodSeconds: 10
ports:
- containerPort: 3000
name: nest-api-blog
restartPolicy: Always
使用 apply 创建实例:
kubectl apply -f ./nest-api-blog.yaml
kubectl get pod # 查看pod列表及运行状态
kubectl get deployment # 查看部署应用列表
kubectl delete deployment <app-name> # 下线应用
kubectl get service # 查看集群内IP/外部IP/端口