国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

kubernetes 基本用法

ChristmasBoy / 2084人閱讀

摘要:所以,我們使用或訪問(wèn)是不合適的,我們需要提供一個(gè)固定及端口。創(chuàng)建一個(gè)用法創(chuàng)建現(xiàn)在,我們就可以在節(jié)點(diǎn)上通過(guò)訪問(wèn)。我們創(chuàng)建一個(gè)客戶端,來(lái)測(cè)試查看的解析,發(fā)現(xiàn)是。在瀏覽器訪問(wèn)發(fā)現(xiàn)是可以訪問(wèn)的未截圖使用任意的均可

創(chuàng)建一個(gè)deployment
[root@master ~]# kubectl run --help
Create and run a particular image, possibly replicated. 
Creates a deployment or job to manage the created container(s).
Usage:
  kubectl run NAME --image=image [--env="key=value"] [--port=port] [--replicas=replicas] [--dry-run=bool]
[--overrides=inline-json] [--command] -- [COMMAND] [args...] [options]

使用如下命令:

[root@master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 --dry-run=true
deployment.apps/nginx-deploy created (dry run)
[root@master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1 
deployment.apps/nginx-deploy created
[root@master ~]# kubectl get deployment
NAME           DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deploy   1         1         1            1           7s
[root@master ~]# kubectl get pod -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP            NODE      NOMINATED NODE
nginx-deploy-5b595999-nzlmj   1/1       Running   0          1m        10.244.2.14   node02    

創(chuàng)建了一個(gè)名為 nginx-deploy 的deployment,副本設(shè)置為1, 查看pod,發(fā)現(xiàn)生成了一個(gè)nginx的pod,且該pod運(yùn)行在node02上,ip為 10.244.2.14 ,檢查node02的網(wǎng)絡(luò)

[root@node02 ~]# ip a|grep -A5 cni0
5: cni0:  mtu 1450 qdisc noqueue state UP qlen 1000
    link/ether 0a:58:0a:f4:02:01 brd ff:ff:ff:ff:ff:ff
    inet 10.244.2.1/24 scope global cni0
       valid_lft forever preferred_lft forever
    inet6 fe80::980e:b1ff:fee7:a26f/64 scope link 
       valid_lft forever preferred_lft forever
8: veth23ea238e@if3:  mtu 1450 qdisc noqueue master cni0 state UP 
    link/ether 32:26:f6:cb:a0:9f brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet6 fe80::3026:f6ff:fecb:a09f/64 scope link 
       valid_lft forever preferred_lft forever

可以發(fā)現(xiàn),pod是跑在cni網(wǎng)橋上的

Pod此時(shí)可以在節(jié)點(diǎn)端通過(guò)Pod ip訪問(wèn)。

當(dāng)我們刪除這個(gè)pod后,Deployment會(huì)重新創(chuàng)建一個(gè)pod,該pod的ip就會(huì)變化。

[root@master ~]# kubectl get pod -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP            NODE      NOMINATED NODE
nginx-deploy-5b595999-nzlmj   1/1       Running   0          1m        10.244.2.14   node02    
[root@master ~]# kubectl delete pod nginx-deploy-5b595999-nzlmj
pod "nginx-deploy-5b595999-nzlmj" deleted
[root@master ~]# kubectl get pod -o wide
NAME                          READY     STATUS    RESTARTS   AGE       IP            NODE      NOMINATED NODE
nginx-deploy-5b595999-z76bn   1/1       Running   0          4s        10.244.1.16   node01    

所以,我們使用pod ip或pod hostname訪問(wèn)是不合適的,我們需要提供一個(gè)固定ip及端口。service可以滿足要求。

創(chuàng)建一個(gè)service

用法

[root@master ~]# kubectl expose --help
Expose a resource as a new Kubernetes service. 
Usage:
  kubectl expose (-f FILENAME | TYPE NAME) [--port=port] [--protocol=TCP|UDP] [--target-port=number-or-name]
[--name=name] [--external-ip=external-ip-of-service] [--type=type] [options]

創(chuàng)建service

[root@master ~]# kubectl expose deployment nginx-deploy --name=nginx --port=80 --target-port=80 --protocol=TCP
service/nginx exposed
[root@master ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1               443/TCP   8h
nginx        ClusterIP   10.101.41.108           80/TCP    7s

現(xiàn)在,我們就可以在節(jié)點(diǎn)上通過(guò)ip 10.101.41.108 訪問(wèn)。在節(jié)點(diǎn)外部無(wú)法訪問(wèn)。

這類地址,更多時(shí)候是被pod客戶端訪問(wèn)的。

我們創(chuàng)建一個(gè)pod客戶端,來(lái)測(cè)試:

[root@master ~]# kubectl run client --image=busybox --replicas=1 -it --restart=Never
If you don"t see a command prompt, try pressing enter.
/ # cat /etc/resolv.conf 
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
/ # 

查看pod的dns解析,發(fā)現(xiàn)nameserver是 10.96.0.10這個(gè)ip是coredns的service ip

[root@master ~]# kubectl get svc -n kube-system -o wide
NAME       TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE       SELECTOR
kube-dns   ClusterIP   10.96.0.10           53/UDP,53/TCP   9h        k8s-app=kube-dns

此時(shí),在busybox這個(gè)pod里,我們可以直接通過(guò)service name nginx 訪問(wèn)之前創(chuàng)建的service,而不是service的ip:port。

# busybox里
/ # wget nginx
Connecting to nginx (10.101.41.108:80)
index.html           100% |**************************************************************************************|   612  0:00:00 ETA
/ # wget -O - -q http://nginx:80 



Welcome to nginx!