1、deployment文件 

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app
  namespace: demo
spec:
  selector:
    matchLabels:
     app: demo-app
  replicas: 1 
  template:
    metadata:
      labels:
        app: demo-app
    spec:
      imagePullSecrets:
      - name:  regcred
      containers:
      - name: demo-app
        image: harbor.cloud.com/test/demo-app:test
        imagePullPolicy: Always
        env:
        - name: HOSTNAME
          value: "demo-app"
        - name: SPRING_PROFILES_ACTIVE
          value: "dev"
        - name: SERVER_PORT
          value: 8014
        - name: NACOS_ADDRESS
          value: "192.168.7.1"
        - name: NACOS_PORT
          value: 8848
        - name: NACOS_GROUP
          value: "demo"
        ports:
        - containerPort: 8014
      hostNetwork: true

2、service文件 

apiVersion: v1
kind: Service
metadata:
  name: demo-app
  namespace: demo
spec:
  selector:
    app: demo-app
  ports:
  - port: 8014
    targetPort: 8014

 3、deployment+service文件

apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo-app
  namespace: demo
spec:
  selector:
    matchLabels:
     app: demo-app
  replicas: 1 
  template:
    metadata:
      labels:
        app: demo-app
    spec:
      imagePullSecrets:
      - name:  regcred
      containers:
      - name: demo-app
        image: harbor.cloud.com/test/demo-app:test
        imagePullPolicy: Always
        env:
        - name: HOSTNAME
          value: "demo-app"
        - name: SPRING_PROFILES_ACTIVE
          value: "dev"
        - name: SERVER_PORT
          value: 8014
        - name: NACOS_ADDRESS
          value: "192.168.7.1"
        - name: NACOS_PORT
          value: 8848
        - name: NACOS_GROUP
          value: "demo"
        ports:
        - containerPort: 8014
      hostNetwork: true

---

apiVersion: v1
kind: Service
metadata:
  name: demo-app
  namespace: demo
spec:
  selector:
    app: demo-app
  ports:
  - port: 8014
    targetPort: 8014

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐