ClusterIP

---
apiVersion: v1
kind: Service
metadata:
  name: myapp-svc
  labels:
    app: myapp
    release: stable
spec:
  # 通过标签关联Pods
  selector:
    app: myapp
    release: stable
  type: ClusterIP
  ports:
  - name: myapp
    # Service 端口
    port: 80
    protocol: TCP
    # 容器暴露端口,可以是端口号,也可以引用容器端口名称
    # 这样做的好处在于,如果后端Pods端口改变,Service跟着更新
    # targetPort: 80
    targetPort: app-port
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  # 副本数
  replicas: 3
  # 只保留最近三次历史RS
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: myapp
      release: stable
  # 滚动更新策略
  strategy: 
    type: RollingUpdate
    # 逐个更新
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      name: myapp-container
      namespace: default
      labels:
        app: myapp
        release: stable
    spec:
      containers:
      - name: myapp-container
        image: ikubernetes/myapp:v1
        ports:
        - name: app-port
          containerPort: 80
          protocol: TCP

results matching ""

    No results matching ""