k8s of service

 K8s three networks : node network

pod network

cluster network -> virtual ip ->  service rules

 

 

service: kube-proxy monitor api-server, api-server data changes, the corresponding kube-proxy will change service rules ,

service has three operating modes userspace, 1.1: previous versions

                                     iptables, 1.10 before

                                     the IPVS , 1.11 after release

 

kubectl delete svc redis

                    service  service

 

 

kubectl explain service

kubectl explain service.spec

 

 

service type :

ExternalName,  service outside the cluster reference to the cluster  external service name

ClusterIP,  only for intra-cluster communication

NodePort,  for communication with external cluster

LoadBalancer, deployed to the virtual machine , the virtual machine to work in the environment , the cloud environment supports load balancing , lbaas, similar nodeport load balancing

 

 

The list of documents created service

ClusterIP,  only for intra-cluster communication   access service first point clusterip, pointing pod ip

kubectl explain service.spec.ports

vim redis-svc.yaml

apiVersion: v1

kind: Service

metadata:

  name: redis service name

  namespace: default

spec:

  selector:   Selected pod tag  associated pod

    app: redis 

    role: logstor

  clusterIP: 10.97.97.97  set clusterip

  type: ClusterIP  selected clusterip type of service

  ports:

  - port: 6379 service port referenced service port with the backend pod relationship

    targetPort: 6379   specified pod port

 

kubectl apply -f redis-svc.yaml  create service

kubectl get svc  inquiry service

kubectl describe svc redis service-redis details

Endpoints: 10.244.1.66:6379   back-end address, that is associated with the pod address

 

 

Resource records: SVC_NAMe.NS_NAME.DOMAIN.LTD.

          Service Name  namespace    cluster domain name suffixes

 

 

       Clusters default domain name suffix  svc.cluster.local.

      For example: just create a service called redis,   then the domain name :

           redis.default.svc.cluster.local.

 

       Direct access to the domain name to access the service, and to resolve pod address the

 

nodeport default port assignment 30000-32797

Creating nodeport Service

Quoted earlier deploy controller myapp-deploy creation of pod

cp Redi-svc.yaml myapp-svc.yaml

vim myapp-svc.yaml

apiVersion: v1

kind: Service

metadata: service attributes

  name: myapp

  namespace: default

spec:

  selector:

    app: myapp  associated with pod

    release: canary

  clusterIP: 10.99.99.99 指定clusterip

  type: NodePort   specified service type

  ports:

  - port: 80 service port

   targetPort: 80  associated pod port

   nodePort: 30080   external access node port

 

  

kubectl create -f myapp-svc.yaml   create service

kubectl get svc

80:30080/TCP

service port 80   mapping   node port 30080

test

Access to any node on the outside such 192.168.81.10:30080

while true; do curl http://192.168.81.30:30080/;sleep 1;done

 

 

ExternalName

Within the cluster pod outside the cluster to access resources,

kubectl explain svc.spec.externalName

 

 

sessionAffinity

kubectl explain svc.spec

 sessionAffinity <string>   maintain session IP same IP request is always sent to the same backend pod

kubectl patch svc myapp -p '{"spec":{"sessionAffinity":"ClientIP"}}'

 

kubectl describe svc myapp  see if adding sessionAffinity

 

kubectl patch svc myapp -p '{ "  spec": { "sessionAffinity": "None"}}' back to None, it will not always sent to a pod

 

 

headless   Headless service headless Services service directly to the pod IP

cp-svc.yaml myapp myapp-headless.yaml

vim myapp-headless.yaml

apiVersion: v1

kind: Service

metadata:

  name: myapp-svc

  namespace: default

spec:

  selector:

    app: myapp

    release: canary

  clusterIP: None

  ports:

  - port: 80

targetPort: 80

 

 kubectl apply -f myapp-headless.yaml

kubectl get svc

 

Installation dig command yum install bind-utils -y

Query coreDns

kubectl get svc -n kube-system

Analytical service

    dig -t A myapp-svc.default.svc.cluster.local. @10.96.0.10

                    @ Domain name service specified coredns

The analytical results for the back-end pod of ip

        

 

For the previous service type clusterip of

dig -t A myapp.default.svc.cluster.local. @10.96.0.10

Analytical results for the CLUSTER-IP

Guess you like

Origin www.cnblogs.com/leiwenbin627/p/11300746.html