k8s-应用快速入门(ma)

[root@k8s-master ~]# kubectl run nginx-deploy --image=nginx:1.14-alpine --port=80 --replicas=1
deployment "nginx-deploy" created

[root@k8s-master ~]# kubectl expose deployment nginx-deploy --name nginx --port=80 --target-port=80 --protocol=TCP  ###target-port等于上图pod_port,--port等于service_port
service "nginx" exposed   

[root@k8s-master ~]# kubectl run busybox-client --image=busybox --replicas=1 -it --restart=Never    ###启动一个busybox pod ,作为客户端
If you don't see a command prompt, try pressing enter.
/ #

[root@k8s-master ~]# kubectl get pod
NAME READY STATUS RESTARTS AGE
busybox-client 1/1 Running 0 1d
frontend-7t8x9 1/1 Running 0 2d
frontend-8jf5h 1/1 Running 0 2d
frontend-vmh7n 1/1 Running 0 2d
nginx-deploy-5b595999-rd9cx 1/1 Running 0 1d
redis-master-gk58w 1/1 Running 0 2d
redis-slave-sjtvf 1/1 Running 0 2d
redis-slave-znn7x 1/1 Running 0 2d

[root@k8s-master ~]# kubectl exec -it nginx-deploy-5b595999-rd9cx -c nginx-deploy /bin/sh     ###进入到客户端

[root@k8s-master src]# kubectl attach po/busybox-client -c busybox-client -it     ###启动客户端

/ # cat /etc/resolv.conf
nameserver 10.10.10.2
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

/ # nslookup nginx
Server: 10.10.10.2
Address: 10.10.10.2:53

Name: nginx.default.svc.cluster.local
Address: 10.10.10.18

/ # wget -O - -q http://nginx:80            ####可以解析nginx
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

[root@k8s-node02 ~]# dig -t A nginx.default.svc.cluster.local @10.10.10.2

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

;; QUESTION SECTION:
;nginx.default.svc.cluster.local. IN    A

;; ANSWER SECTION:
nginx.default.svc.cluster.local. 30 IN  A       10.10.10.18

;; Query time: 0 msec
;; SERVER: 10.10.10.2#53(10.10.10.2)
;; WHEN: Wed Jun 05 08:09:11 EDT 2019
;; MSG SIZE  rcvd: 65

从上可以看到,kube-dns已经安装成功!!!

原文地址:https://www.cnblogs.com/shanhua-fu/p/10981283.html