Service的几种发布方式

Service的发布方式主要有三种:

Cluster IP, NodePort, LoadBalancer

1. 先来看看Cluster IP,

1)cluster_ip.yaml, 在此yaml文件中,service的yaml里没有定义任何type,那么就用默认的cluster ip type

apiVersion: v1
kind: Service
metadata:
  name: webapp1-clusterip-svc
  labels:
    app: webapp1-clusterip
spec:
  ports:
  - port: 80
  selector:
    app: webapp1-clusterip
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp1-clusterip-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: webapp1-clusterip
    spec:
      containers:
      - name: webapp1-clusterip-pod
        image: katacoda/docker-http-server:latest
        ports:
        - containerPort: 80
---

2)设置环境变量

     export CLUSTER_IP=$(kubectl get services/webapp1-clusterip-svc -o go-template='{{(index .spec.clusterIP)}}')

     echo CLUSTER_IP=$CLUSTER_IP

     curl $CLUSTER_IP:80

3)由上一步可显示k8s自动分配给service的cluster ip

 

上一篇:networkpolicy


下一篇:k8s 数据卷概述