Kubernets external access

First, the concept

Are three external access methods Kubernetes of: NodePort , LoadBalancer and Ingress

1、NodePort

  External service is to guide traffic to the most primitive way of your service. Open a specific port on all nodes (virtual machine), any traffic sent to the port will be forwarded to the corresponding service. 30000-32767 port range only

2、Ingress

  The most powerful way to expose services, Ingress controller has various types, more commonly used Ingress Nginx (kubernets official maintenance), Traefik , Voyager , Ingress Kong

3、LoadBalancer

  Services are exposed to a standard way of internet service. On GKE, this approach will start a Network Load Balancer [2], it will give you a single IP address, to forward all traffic to your service

Second, the deployment test

 Here deployed with NodePort, Ingress, most commonly used in two ways

 Application deployment: https://www.cnblogs.com/fanxp/p/12084733.html

1、NodePort

apiVersion: v1 
kind: Service 
the Metadata: 
  name: nginx - Service 
spec: 
  Selector: 
    App: nginx 
  # exposure patterns 
  of the type: NodePort 
  the ports: 
    # Service Internal Access Port
   - Port: 8080 
    # POD port 
    TARGETPORT: 80 
    # of external exposure port (if you do not write default random 30000 - 32767 ) 
    nodePort: 30003

View:

# Load the configuration 
kubectl the Apply - f nginx.yaml 
# View Service 
kubectl GET Service

 

 Find outside a computer browser: http://192.168.1.9:30003/  here ip ip address into node Renyiyitai

 

 2、Ingress

  As used herein kubernetes maintenance Ingress Nginx

  • helm v3 Installation
  • helm installation Ingress Nginx

 All versions helm: https://github.com/helm/helm/releases

# Download Helm 
curl -SLO https://get.helm.sh/helm-v3. 0.2 -linux- amd64.tar.gz 
# unpack 
tar -zxvf Helm-v3. 0.2 -linux- amd64.tar.gz 
# Move / bin directory 
mv Linux -amd64 / Helm / usr / local / bin / Helm 
# verify 
helm version

# Add repo 
Helm repo the Add stable HTTPS: // kubernetes- charts.storage.googleapis.com 
# aliyun repo (not tested) 
Helm repo the Add stable HTTPS: //kubernetes.oss-cn-hangzhou.aliyuncs.com/ Charts 
# View 
repo helm repo list

# 查看node ip
kubectl get nodes -o wide
# 安装nginx-ingress(controller.service.externalIPs[0]=node ip)
helm install nginx-ingress stable/nginx-ingress --set "controller.service.externalIPs[0]=192.168.1.222,controller.service.externalIPs[1]=192.168.1.9"

nginx.yaml

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: nginx-service-ingress
spec:
  rules:
    # 域名
  - host: nginx.fanxp.com
    http:
      paths:
      - backend:
          serviceName: nginx-service
          servicePort: 8080
        path: /

View ingress

kubectl get ingress

 

 If it is a local area network, the client host file with

192.168.1.222 nginx.fanxp.com

Access in the browser: nginx.fanxp.com can see the same effect and NodePort

Interested can enter the pod nginx-ingress-controller View nginx.conf generation rules

Exec -it nginx-Ingress kubectl-the Controller-775b4967cb- w4rc7 SH 
# View 
cat nginx.conf

Guess you like

Origin www.cnblogs.com/fanxp/p/12091408.html