Bootstrap

k8s部署文件

k8s部署文件 以及 service暴露文件

在项目deploy下创建prod/prod.yaml

#资源类型
kind: Deployment
apiVersion: apps/v1
metadata:
#与微服务一样
  name: gulimall-order
#k8s的项目名
  namespace: gulimall
  labels:
 #与微服务一样
    app: gulimall-order
#规格
spec:
#副本数量
  replicas: 1
#选择器
  selector:
  #匹配labels 与上面labels名字相同
    matchLabels:
      app: gulimall-order
  #模板
  template:
    metadata:
      labels:
      #匹配labels 与上面labels名字相同
        app: gulimall-order
    #规格
    spec:
      containers:
      #容器名
        - name: gulimall-order
		#镜像地址 动态取值
          image: $REGISTRY/$DOCKERHUB_NAMESPACE/$PROJECT_NAME:latest
          ports:
          #容器端口
            - containerPort: 8080
              protocol: TCP
			#资源
          resources:
          #限制
            limits:
              cpu: 1000m
              memory: 500Mi
              #初始申请
            requests:
              cpu: 10m
              memory: 10Mi
              #日志存放位置
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          #镜像不存在再拉取
          imagePullPolicy: IfNotPresent
          #自动重启
      restartPolicy: Always
      #停机秒数
      terminationGracePeriodSeconds: 30
      #策略
  strategy:
  #滚动更新策略 停一个起一个
    type: RollingUpdate
    rollingUpdate:
    #最大不可用
      maxUnavailable: 25%
      #最大存活
      maxSurge: 25%
      #历史版本数量
  revisionHistoryLimit: 10
  #处理时间
  progressDeadlineSeconds: 600

---
#无状态服务
kind: Service
apiVersion: v1
#与上相同
metadata:
  name: gulimall-order
  namespace: gulimall
  labels:
    app: gulimall-order
#规格
spec:
  ports:
    - name: http
      protocol: TCP
      port: 8080 #暴露端口
      targetPort: 8080 #启动端口
      nodePort: 31005 #代理端口
  selector:
    app: gulimall-order
  type: NodePort #以nodeport方式暴露
  sessionAffinity: None #无需会话

port,targetport,nodeport

在这里插入图片描述
除了nodeport 不能一样 其他可以一样 因为我们每个pod是隔离的每个service也是隔离的

作者声明

如有问题,欢迎指正!
;