本文共 7389 字,大约阅读时间需要 24 分钟。
创建CoreDNS
[root@k8smaster coredns]# lscoredns.yaml[root@k8smaster coredns]# kubectl create -f .serviceaccount "coredns" createdclusterrole.rbac.authorization.k8s.io "system:coredns" createdclusterrolebinding.rbac.authorization.k8s.io "system:coredns" createdconfigmap "coredns" createddeployment.extensions "coredns" createdservice "coredns" created创建Dashboard
[root@k8smaster addons]# cd dashboard/[root@k8smaster dashboard]# lsadmin-user-sa-rbac.yaml kubernetes-dashboard.yaml ui-admin-rbac.yaml ui-read-rbac.yaml[root@k8smaster dashboard]# kubectl create -f .serviceaccount "admin-user" createdclusterrolebinding.rbac.authorization.k8s.io "admin-user" createdsecret "kubernetes-dashboard-certs" createdserviceaccount "kubernetes-dashboard" createdrole.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" createdrolebinding.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" createddeployment.apps "kubernetes-dashboard" createdservice "kubernetes-dashboard" createdclusterrole.rbac.authorization.k8s.io "ui-admin" createdrolebinding.rbac.authorization.k8s.io "ui-admin-binding" createdclusterrole.rbac.authorization.k8s.io "ui-read" createdrolebinding.rbac.authorization.k8s.io "ui-read-binding" created[root@k8smaster dashboard]# kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
Name: admin-user-token-hxlzjNamespace: kube-systemLabels: <none>Annotations: kubernetes.io/service-account.name=admin-userkubernetes.io/service-account.uid=515020bb-6ec5-11e8-bf01-000c29007455Type: kubernetes.io/service-account-token
ca.crt: 1359 bytes
namespace: 11 bytestoken: eyJhbGciOiJSUzI1NiIsImtpZCI6IiJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJhZG1pbi11c2VyLXRva2VuLWh4bHpqIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6ImFkbWluLXVzZXIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiI1MTUwMjBiYi02ZWM1LTExZTgtYmYwMS0wMDBjMjkwMDc0NTUiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZS1zeXN0ZW06YWRtaW4tdXNlciJ9.lqSmY5ZKhJ_s7czQs8Mif-a6pkSPU3OC3UzobE095HYlm3fn_l66bEIBV9-7BXdl9vyWch1g8Aryr0zyFrhjJxhK9t7eEzmLHP3qm3BjyTa4LlrKXxffkXpXiOSSlYxx4ZuExKO7rvvEtwEQUoru1eOGVRPJQwCfSMZsNQp27bBa6ocMgYJqOSqgd8iR76vq8RYKmOVGQRDbY_iVGZb_VGcFFGZexx8miPlgbk3zHjx9ENivIU9K9huoUsx505cpsCQWc-wz7_DTfKeOedmxh3e1ebUzDo9ww1pd-05sgN0GovuAEXtpoanGEVBaFPGoB3wb3b6ilyxY3FDHzFrTLA查看状态
[root@k8smaster dashboard]# kubectl get pods -o wide -n kube-systemNAME READY STATUS RESTARTS AGE IP NODEcoredns-77c989547b-4dfnn 1/1 Running 5 11m 10.2.59.3 k8snode2coredns-77c989547b-54s8d 1/1 Running 6 11m 10.2.57.3 k8snode1kubernetes-dashboard-66c9d98865-txvx2 1/1 Running 2 1m 10.2.57.4 k8snode1[root@k8smaster dashboard]# kubectl get services -o wide -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORcoredns ClusterIP 10.1.0.2 <none> 53/UDP,53/TCP 12m k8s-app=corednskubernetes-dashboard ClusterIP 10.1.72.67 <none> 443/TCP 10m k8s-app=kubernetes-dashboard[root@k8smaster dashboard]# kubectl cluster-infoKubernetes master is running at CoreDNS is running at kubernetes-dashboard is running atTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@k8smaster ~]# kubectl cluster-info
Kubernetes master is running at CoreDNS is running at kubernetes-dashboard is running atTo further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
[root@k8smaster ~]# kubectl get services -o wide -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORcoredns ClusterIP 10.1.0.2 <none> 53/UDP,53/TCP 19m k8s-app=corednskubernetes-dashboard ClusterIP 10.1.150.142 <none> 443/TCP 9m k8s-app=kubernetes-dashboard[root@k8smaster ~]#[root@k8smaster ~]# kubectl get pods -o wide -n kube-systemNAME READY STATUS RESTARTS AGE IP NODEcoredns-77c989547b-8tbcs 1/1 Running 0 7m 10.2.59.7 192.168.137.198coredns-77c989547b-gzz2g 1/1 Running 0 7m 10.2.36.6 192.168.137.201kubernetes-dashboard-66c9d98865-fk2lb 1/1 Running 0 8m 10.2.36.5 192.168.137.2012
3
1、创建应用一:
[root@k8smaster ~]# kubectl run net-test --image=alpine --replicas=2 sleep 360000deployment.apps "net-test" created[root@k8smaster ~]#[root@k8smaster ~]# kubectl get podsNAME READY STATUS RESTARTS AGEnet-test-5767cb94df-v8w6n 0/1 ContainerCreating 0 38snet-test-5767cb94df-z5xgm 0/1 ContainerCreating 0 37s[root@k8smaster ~]#[root@k8smaster ~]# kubectl get podsNAME READY STATUS RESTARTS AGEnet-test-5767cb94df-v8w6n 1/1 Running 0 2mnet-test-5767cb94df-z5xgm 1/1 Running 0 2m[root@k8smaster ~]#[root@k8smaster ~]# kubectl get pod -o wideNAME READY STATUS RESTARTS AGE IP NODEnet-test-5767cb94df-v8w6n 1/1 Running 0 2m 10.2.59.2 k8snode2net-test-5767cb94df-z5xgm 1/1 Running 0 2m 10.2.57.2 k8snode1[root@k8smaster ~]# ping 10.2.59.2 -c 4PING 10.2.59.2 (10.2.59.2) 56(84) bytes of data.64 bytes from 10.2.59.2: icmp_seq=1 ttl=63 time=1.01 ms64 bytes from 10.2.59.2: icmp_seq=2 ttl=63 time=0.647 ms64 bytes from 10.2.59.2: icmp_seq=3 ttl=63 time=1.34 ms64 bytes from 10.2.59.2: icmp_seq=4 ttl=63 time=0.702 ms--- 10.2.59.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000msrtt min/avg/max/mdev = 0.647/0.925/1.342/0.278 ms[root@k8smaster ~]# ping 10.2.57.2 -c 4PING 10.2.57.2 (10.2.57.2) 56(84) bytes of data.64 bytes from 10.2.57.2: icmp_seq=1 ttl=63 time=1.92 ms64 bytes from 10.2.57.2: icmp_seq=2 ttl=63 time=0.415 ms64 bytes from 10.2.57.2: icmp_seq=3 ttl=63 time=0.453 ms64 bytes from 10.2.57.2: icmp_seq=4 ttl=63 time=0.483 ms--- 10.2.57.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000msrtt min/avg/max/mdev = 0.415/0.820/1.929/0.640 ms2、创建Nginx
[root@k8smaster ~]# kubectl run nginx --image=nginx --replicas=2deployment.apps "nginx" created[root@k8smaster ~]# kubectl expose deployment nginx --type=NodePort --name=nginx --port=80
service "nginx" exposed[root@k8smaster ~]# kubectl get services -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORkubernetes ClusterIP 10.1.0.1 <none> 443/TCP 7h <none>nginx NodePort 10.1.133.181 <none> 80:32109/TCP 6s run=nginx[root@k8smaster ~]#[root@k8smaster ~]# kubectl get pods -o wideNAME READY STATUS RESTARTS AGE IP NODEnginx-65899c769f-nwxw4 1/1 Running 0 4m 10.2.59.6 192.168.137.198nginx-65899c769f-sxq7m 1/1 Running 0 4m 10.2.36.3 192.168.137.201Nginx访问成功!
[root@k8snode1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConnTCP 192.168.137.201:32109 rr-> 10.2.36.3:80 Masq 1 1 0 -> 10.2.59.6:80 Masq 1 1 0 TCP 192.168.137.215:32109 rr-> 10.2.36.3:80 Masq 1 0 0 -> 10.2.59.6:80 Masq 1 0 0 TCP 10.1.0.1:443 rr persistent 10800-> 192.168.137.171:6443 Masq 1 0 0 TCP 10.1.0.2:53 rr-> 10.2.59.4:53 Masq 1 0 0 TCP 10.1.72.67:443 rrTCP 10.1.133.181:80 rr-> 10.2.36.3:80 Masq 1 0 0 -> 10.2.59.6:80 Masq 1 0 0 TCP 10.2.36.0:32109 rr-> 10.2.36.3:80 Masq 1 0 0 -> 10.2.59.6:80 Masq 1 0 0 TCP 10.2.36.1:32109 rr-> 10.2.36.3:80 Masq 1 0 0 -> 10.2.59.6:80 Masq 1 0 0 TCP 127.0.0.1:32109 rr-> 10.2.36.3:80 Masq 1 0 0 -> 10.2.59.6:80 Masq 1 0 0 UDP 10.1.0.2:53 rr-> 10.2.59.4:53 Masq 1 0 0转载于:https://blog.51cto.com/andyliu/2129078