Several ways kubernetes exposed port services
If you want to Service exposed on an external IP address. Kubernetes supports 4 implementation, detailed as follows:
1: Within a cluster for access: Clusterip
Clusterip internal cluster private ip, very convenient to access the service in the cluster, the cluster is kuberentes default way to access service through direct Clusterip, it can also be accessed directly by ServiceName. Outside the cluster it is inaccessible.
2: Cluster external access: NodePort
NodePort in kubenretes there is a widely used service early exposure mode. ClusterIP under service default Kubernetes of this type are used, this service will have a ClusterIP, the IP can only be accessed within the cluster, to get an external service can be accessed directly, you need to modify the service type is nodePort. The mapping service listening port node to node.
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-dm
spec:
replicas: 2
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-svc
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30004
protocol: TCP
selector:
name: nginx
create
kubectl create -f nginx-ds.yaml
Access tests
In addition to the cluster, a node can be any node ip: the cluster can access the service nodeport
3:LoadBalancer
LoadBlancer Service is a component of kubernetes depths with cloud platform; LoadBlancer Service exposed when using the service, in fact, on application to the underlying cloud platform to create a load balancer to expose services outside; LoadBlancer Service currently supported cloud platform has been relatively well such as foreign GCE, DigitalOcean, domestic Ali cloud, private cloud Openstack, etc., due to the depth LoadBlancer Service combines cloud platform, you can only use up some cloud platform.
4:Ingress
Ingress is a resource type version introduced since the kubernetes1.1. Ingress controller must be deployed in order to create Ingress resources, Ingress controller is a form of plug-ins available.
Ingress more widely used are: nginx and traefik, personally recommend using traefik.