成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

kubernetes 基本用法

ChristmasBoy / 2091人閱讀

摘要:所以,我們使用或訪問是不合適的,我們需要提供一個(gè)固定及端口。創(chuàng)建一個(gè)用法創(chuàng)建現(xiàn)在,我們就可以在節(jié)點(diǎn)上通過訪問。我們創(chuàng)建一個(gè)客戶端,來測試查看的解析,發(fā)現(xiàn)是。在瀏覽器訪問發(fā)現(xià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)端通過Pod ip訪問。

當(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訪問是不合適的,我們需要提供一個(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)上通過ip 10.101.41.108 訪問。在節(jié)點(diǎn)外部無法訪問。

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

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

[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里,我們可以直接通過service name nginx 訪問之前創(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!