Monday, January 13, 2020

kubernetes - how to local load balancer

Pre-requirements:
  1. Docker desktop installed.
  2. Kubernetes enabled
  3. Some services already created and running:
kubectl.exe get all                                                            
NAME                             READY STATUS RESTARTS AGE                
pod/httpenv-dd7475946-69wj8      1/1     Running   0          15h              
pod/httpenv-dd7475946-6ncsb      1/1     Running   0          15h              
pod/httpenv-dd7475946-cf46s      1/1     Running   0          15h              
pod/httpenv-dd7475946-lclml      1/1     Running   0          15h               pod/httpenv-dd7475946-nv4br      1/1     Running   0          15h                                                                                               
NAME                 TYPE CLUSTER-IP       EXTERNAL-IP PORT(S) AGE  
service/httpenv      ClusterIP 10.111.175.59    <none>        8888/TCP   15
                                                                                 
NAME                        READY UP-TO-DATE AVAILABLE   AGE
deployment.apps/httpenv     5/5     5            5           15h               
               
                                                                               
NAME                                   DESIRED CURRENT READY AGE    
replicaset.apps/httpenv-dd7475946      5         5         5       15h         

Create LoadBalancer:
  1. Create LoadBalancer as following
kubectl.exe expose deployment.apps/httpenv --port 8888 --name httpenv-lb --type LoadBalancer                                                                     
service/httpenv-lb exposed        
  1. Check the load balancer created
kubectl.exe get service                                                            
NAME         TYPE           CLUSTER-IP       EXTERNAL-IP PORT(S)          AGE
httpenv      ClusterIP   10.111.175.59   <none> 8888/TCP         15h
httpenv-lb   LoadBalancer   10.102.229.139   localhost 8888:31050/TCP   28s          
                                                                                                                                                                       
  1. Test                                                                                                                                                                               
curl localhost:8888                                                                                                                                                                                                                        
{"HOME":"/root","HOSTNAME":"httpenv-dd7475946-cf46s","KUBERNETES_PORT":"tcp://10.96.0.1:443","KUBERNETES_PORT_443_TCP":"tcp://10.96.0.1:443","KUBERNETES_PORT_443_TCP_ADDR":"10.96.0.1","KUBERNETES_PORT_443_TCP_PORT":"443","KUBERNETES_PORT_
443_TCP_PROTO":"tcp","KUBERNETES_SERVICE_HOST":"10.96.0.1","KUBERNETES_SERVICE_PORT":"443","KUBERNETES_SERVICE_PORT_HTTPS":"443","NGINX_HTTP_PORT":"tcp://10.101.186.145:8083","NGINX_HTTP_PORT_8083_TCP":"tcp://10.101.186.145:8083","NGINX_H
TTP_PORT_8083_TCP_ADDR":"10.101.186.145","NGINX_HTTP_PORT_8083_TCP_PORT":"8083","NGINX_HTTP_PORT_8083_TCP_PROTO":"tcp","NGINX_HTTP_SERVICE_HOST":"10.101.186.145","NGINX_HTTP_SERVICE_PORT":"8083","PATH":"/usr/local/sbin:/usr/local/bin:/usr
/sbin:/usr/bin:/sbin:/bin"}                                                                                                                                                                                                                   

No comments:

Post a Comment