service-ClusterIP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
spec:
  # 副本数
  replicas: 3 
  selector: 
    matchLabels:
      app: nginx-clusterip
  template:
    metadata:
      labels:
        app: nginx-clusterip
    spec:
      containers:
      - name: nginx-clusterip
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-clusterip-svc
spec:
  type: ClusterIP
  selector:
    app: nginx-clusterip
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80

service-NodePort

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-nodeport
spec:
  # 副本数
  replicas: 3 
  selector: 
    matchLabels:
      app: nginx-nodeport
  template:
    metadata:
      labels:
        app: nginx-nodeport
    spec:
      containers:
      - name: nginx-nodeport
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport-svc
spec:
  type: NodePort
  selector:
    app: nginx-nodeport
  ports:
  - protocol: TCP
    nodePort: 30001
    port: 80
    targetPort: 80