daemonset 和 service服務(wù)

nodeport?和ClusterIPapiVersion: v1kind: Service#apiVersion: v1#kind: Servivemetadata:??name: nginx-svc??namespace: defaultspec:??type: NodePort??#定義類型為NodePort??selector:??#標(biāo)簽選擇,把需要轉(zhuǎn)發(fā)的后端的標(biāo)簽寫(xiě)在下面? ??app: nginx??ports:??- port: 80? ? #service端口? ??targetPort: 80? ? #容器端口? ??nodePort: 30080? ? #node端口,如果是ClusterIP的這段不需要,也可以不填會(huì)隨機(jī)---apiVersion: v1kind: Podmetadata:??name: ng1??labels:? ? app: webspec:??containers:? ? - name: ng1? ?? ?image:??hub.c.163.com/library/nginx? ?? ?imagePullPolicy: IfNotPresentnodeport?和ClusterIP?用法差不多就類型填的不一樣,還有ClusterIP不用填nodePort
Deployment控制器apiVersion: v1kind: Servicemetadata:name: nginx-svcnamespace: defaultspec:type: NodePort#定義類型為NodePortselector:#標(biāo)簽選擇,把需要轉(zhuǎn)發(fā)的后端的標(biāo)簽寫(xiě)在下面? ??app: webports:- port: 90? ? #service端口? ??targetPort: 80? ? #容器端口? ??nodePort: 30080? ? #node端口,如果是ClusterIP的這段不需要,也可以不填會(huì)隨機(jī)---apiVersion: apps/v1kind: Deploymentmetadata:name: nginxspec:replicas: 2#表示啟動(dòng)兩個(gè)容器selector:? ? matchLabels:? ?? ?? ?? ?app: nginx#匹配標(biāo)簽template:#這下面的和pod寫(xiě)法一樣? ??metadata:? ?? ???labels:? ?? ?? ?? ?app: nginx? ? spec:? ?? ???containers:? ?? ???- name: ng1? ?? ?? ?? ?image:??hub.c.163.com/library/nginx? ?? ?? ?? ?imagePullPolicy: IfNotPresent2.daemonset控制器和service無(wú)頭服務(wù)apiVersion: apps/v1kind: DaemonSet#控制器類型dae...,這種控制器會(huì)把每一個(gè)node的節(jié)點(diǎn)都啟動(dòng)一個(gè)下面標(biāo)簽匹配的容器,有污點(diǎn)的除外metadata:??name: nginx-daemonset??namespace: defaultspec:??selector:? ? matchLabels:? ?? ?app: nginx??template:? ? metadata:? ?? ?labels:? ?? ???app: nginx? ? spec:? ?? ?containers:? ?? ?- name: nginx? ?? ???image: "ikubernetes/myapp:v1"---apiVersion: v1kind: Servicemetadata:??name: nginx-service??namespace: defaultspec:??selector:? ? app: nginx??clusterIP: None??ports:??- port: 80? ? targetPort: 80service的無(wú)頭服務(wù)適用于有些服務(wù)直接要和后端的容器建立連接場(chǎng)景使用的
[root@cs25 ~]# kubectl get pod??-l app=myapp -o wideNAME? ?? ?? ?? ?? ?? ?? ?? ?? ? READY? ?STATUS? ? RESTARTS? ?AGE? ?IP? ?? ?? ?? ?? ?NODE? ?NOMINATED NODE? ?READINESS GATESmyapp-deploy-6c7db749dd-4kjdh? ?1/1? ???Running? ?0? ?? ?? ? 31m? ?192.168.94.170? ?cs27? ?<none>? ?? ?? ???<none>myapp-deploy-6c7db749dd-x95d6? ?1/1? ???Running? ?0? ?? ?? ? 31m? ?192.168.100.2? ? cs25? ?<none>? ?? ?? ???<none>#查看兩個(gè)后端容器的ip[root@cs25 ~]# dig nginx-service.default.svc.cluster.local; <<>> DiG 9.9.4-RedHat-9.9.4-72.el7 <<>> nginx-service.default.svc.cluster.local;; global options: +cmd;; Got answer:;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16814;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1;; WARNING: recursion requested but not available;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;nginx-service.default.svc.cluster.local. IN A;; ANSWER SECTION:nginx-service.default.svc.cluster.local. 30 IN A 192.168.100.47nginx-service.default.svc.cluster.local. 30 IN A 192.168.94.168;; Query time: 4 msec;; SERVER: 192.168.100.37#53(192.168.100.37);; WHEN:?一?12月?23 14:03:19 CST 2019;; MSG SIZE??rcvd: 178#解析域名??nginx-service.default.svc.cluster.local?看是不是解析的容器ip,上面可以看到兩個(gè)容器的ip都被解析到了,#如果這邊是service帶ip就會(huì)解析成service ip由service代理至后端容器,無(wú)頭服務(wù)就是直接解析后端容器ip直接和容器建立連接,了解更多相關(guān)內(nèi)容歡迎關(guān)注http://www.vecloud.com/