service basic concepts and operations

sevice Concepts

       service implementation depends strongly on the new version kube-DNS k8s assembly is mounted core-DNS 

       Because each pod is a life cycle in order to provide a client access pod fixed endpoint access

       service is the name of a service intermediate layer between the client and the server parsing pod is strongly dependent on the service dns

Cluster network introduced species

      Pod network address and the network node is a real network address is a corresponding network device (including hardware and software simulated network device)

      service network (cluster network) is a virtual IP address merely forwarding rule iptables or ipvs corresponding network device does not exist

 

service of three implementation models   

   1. The user-space mode
       requests to go through the kernel sub kube-proxy process finally back to the kernel
   2. kernel iptables rules
   3. Kernel ipvs rules

    Add or delete a label conforming selector pod after pod save the information will be submitted to the apiserver to etcd in kube-proxy has been apiserver watch the data inside information

    Upon detection of a change generated in real time will immediately ipvs forwarding rules corresponding to the external request may be forwarded to a corresponding POD
   -Service field specifies the ports

       nodePort "node network port port" service network port targetPort "pod network port

 

service resource record parsing rules

     The overall format SVC_NAME.NS_NAME.DOMAIN.LTD. Clusters suffix svc.cluster.local.

     如  redis.default.svc.cluster.local.

           redis service is the name of a namespace is created .default .svc.cluster.local redis service is located. k8s cluster suffix is ​​added by default

 

kind of service

     Headless service

      Definition of service when the clusterIP set to None on behalf of a headless service
      within the cluster do dns resolve time directly to the service name resolves to ip corresponding to the list of pod

apiVersion: v1
kind: Service
metadata:
  name: myappless
  namespace: default
spec:
  selector:
    app: myapp
  clusterIP: None
  type: ClusterIP
  ports:
  -  port: 80
     targetPort: 80
headless_svc.yaml
     It has a head service    

     If there is, then the head dns resolution service name service when the return is then made on clusterIP clusterIP DNAT to the rear end by respective podIP

apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  selector:
    app: myapp
  clusterIP: 10.96.97.97
  type: ClusterIP
  ports:
  -  port: 80
     targetPort: 80
head_svc.yaml

 

Two different service Comparative analysis results

[root@k8s-master ~]# kubectl get pods -o wide
NAME                            READY     STATUS    RESTARTS   AGE       IP             NODE
myapp-deploy-67f6f6b4dc-248mn   1/1       Running   0          11m       10.244.2.71    node3
myapp-deploy-67f6f6b4dc-5kzk4   1/1       Running   0          11m       10.244.1.147   node2
myapp-deploy-67f6f6b4dc-cglrb   1/1       Running   0          11m       10.244.2.70    node3
myapp-deploy-67f6f6b4dc-fsgrz   1/1       Running   0          11m       10.244.2.69    node3
myapp-deploy-67f6f6b4dc-l5bd7   1/1       Running   0          11m       10.244.1.146   node2
[root@k8s-master ~]# kubectl get svc -n kube-system
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
kube-dns   ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP   233d



[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1     <none>        443/TCP   233d
myapp        ClusterIP   10.96.97.97   <none>        80/TCP    3m
myappless    ClusterIP   None          <none>        80/TCP    12s


# Headless service directly resolved to the corresponding pod
[root@k8s-master ~]# dig -t A myappless.default.svc.cluster.local. @10.96.0.10

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A myappless.default.svc.cluster.local. @10.96.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12827
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;myappless.default.svc.cluster.local. IN    A

;; ANSWER SECTION:
myappless.default.svc.cluster.local. 5 IN A    10.244.1.146
myappless.default.svc.cluster.local. 5 IN A    10.244.1.147
myappless.default.svc.cluster.local. 5 IN A    10.244.2.69
myappless.default.svc.cluster.local. 5 IN A    10.244.2.70
myappless.default.svc.cluster.local. 5 IN A    10.244.2.71

;; Query time: 2 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Mon May 27 02:05:11 CST 2019
;; MSG SIZE  rcvd: 319


# Cap service to resolve the clusterIp
[root@k8s-master ~]# dig -t A myapp.default.svc.cluster.local. @10.96.0.10

; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A myapp.default.svc.cluster.local. @10.96.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40454
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;myapp.default.svc.cluster.local. IN    A

;; ANSWER SECTION:
myapp.default.svc.cluster.local. 5 IN    A    10.96.97.97

;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Mon May 27 02:07:42 CST 2019
;; MSG SIZE  rcvd: 107
View Code
[root@k8s-master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        230d
myapp        NodePort    10.100.165.177   <none>        80:32185/TCP   5m
[root@k8s-master ~]# kubectl run client --image=busybox --restart=Never -it /bin/sh
If you don't see a command prompt, try pressing enter.
/ # wget -O -q http://myapp.default:80
Connecting to myapp.default:80 (10.100.165.177:80)
-q                   100% |*****************************************|    65  0:00:00 ETA
/ # wget -O  - -q http://myapp.default:80
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>
/ # wget -O  - -q http://myapp.default:80
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

[root@k8s-master ~]# wget -O - -q http://myappd.default:80/hostname.html
[root@k8s-master ~]# kubectl get pods
NAME                     READY     STATUS    RESTARTS   AGE
client                   1/1       Running   0          46m
myapp-6865459dff-c59qp   1/1       Running   0          1h
myapp-6865459dff-zd6wg   1/1       Running   0          10m
[root@k8s-master ~]# kubectl exec -it client /bin/sh
/ # wget -O - -q http://myapp.default:80/hostname.html
myapp-6865459dff-zd6wg

pod and pods deployment and deployments can be
[root@k8s-master ~]# kubectl get deployment
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
myapp     2         2         2            2           1h
[root@k8s-master ~]# kubectl get deployments
NAME      DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
myapp     2         2         2 
service commonly used commands

 

Guess you like

Origin www.cnblogs.com/yxh168/p/10926945.html