1、快速搭建文檔html
1、初始化kubernete kubeadm init --kubernetes-version=v1.14.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.10.12 --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers .... To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: kubeadm join 192.168.10.12:6443 --token 3s24j5.nh1fqex8kmekpmtf \ --discovery-token-ca-cert-hash sha256:62bcc3a657fd97cd6d5da14b293912234f0f14512bb4bf8d8be1023a69fc6f17 ========================== 2、安裝flannel網絡 wget https://raw.githubusercontent.com/loverying/mykubernetes/master/kubect_install/kube-flannel.yaml [root@master kubectyaml]# kubectl apply -f kube-flannel.yaml podsecuritypolicy.extensions/psp.flannel.unprivileged created clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/flannel created serviceaccount/flannel created configmap/kube-flannel-cfg created daemonset.extensions/kube-flannel-ds-amd64 created daemonset.extensions/kube-flannel-ds-arm64 created daemonset.extensions/kube-flannel-ds-arm created daemonset.extensions/kube-flannel-ds-ppc64le created daemonset.extensions/kube-flannel-ds-s390x created [root@master kubectyaml]# kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master 2m43s v1.14.2 3、其餘機器加入集羣 kubeadm join 192.168.10.12:6443 --token 3s24j5.nh1fqex8kmekpmtf \ --discovery-token-ca-cert-hash sha256:62bcc3a657fd97cd6d5da14b293912234f0f14512bb4bf8d8be1023a69fc6f17 [root@master kubectyaml]# kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master 4m3s v1.14.2 node01 Ready <none> 27s v1.14.2 node02 Ready <none> 22s v1.14.2 4、部署 dashboard wget https://raw.githubusercontent.com/loverying/mykubernetes/master/kubect_install/dashboard-admin_new.yaml wget https://raw.githubusercontent.com/loverying/mykubernetes/master/kubect_install/kubernetes-dashboard.yaml kubectl apply -f dashboard-admin_new.yaml kubectl apply -f kubernetes-dashboard.yaml 5、部署ingress-nginx wget https://raw.githubusercontent.com/loverying/mykubernetes/master/kubect_install/mandatory.yaml kubectl apply -f mandatory.yaml 6、部署應用 1)部署pod 提供後端服務 2)部署service 是作負載均衡 3)部署ingress-nginx 將負載均衡綁定在域名上 7、部署普羅米修斯監控(研究) 8、日誌收集平臺(研究) EFK平臺
2、部署應用node
1.1)部署podnginx
apiVersion: apps/v1 kind: ReplicaSet metadata: name: myapp namespace: default labels: app: myapp spec: replicas: 2 selector: matchLabels: app: myapp template: metadata: name: myapp-pod labels: app: myapp spec: containers: - name: myapp image: ikubernetes/myapp:v1 ports: - name: http containerPort: 80
1.2)訪問效果git
[root@master ~]# kubectl get pods -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES myapp-8w7bm 1/1 Running 0 10m 10.244.2.7 node02 <none> <none> myapp-n4xhs 1/1 Running 0 10m 10.244.1.8 node01 <none> <none> [root@master ~]# curl 10.244.2.7/hostname.html myapp-8w7bm [root@master ~]# curl 10.244.1.8/hostname.html myapp-n4xhs
2.1)建立servicegithub
apiVersion: v1 kind: Service metadata: name: myapp namespace: default spec: selector: app: myapp clusterIP: 10.99.99.99 type: NodePort ports: - port: 80 targetPort: 80 nodePort: 30080
2.2) 訪問效果後端
[root@master ~]# kubectl get svc -o wide NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3h10m <none> myapp NodePort 10.99.99.99 <none> 80:30080/TCP 8m15s app=myapp [root@master ~]# while true;do curl 192.168.10.12:30080/hostname.html;sleep 1;done myapp-8w7bm myapp-n4xhs myapp-n4xhs myapp-8w7bm myapp-8w7bm
3.1)建立 ingressapi
apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-myapp namespace: default annotations: kubernetes.io/ingress.class: "nginx" spec: rules: - host: master.com http: paths: - backend: serviceName: myapp servicePort: 30080
3.2 ) 訪問效果測試網絡
[root@master ~]# kubectl get ingress NAME HOSTS ADDRESS PORTS AGE ingress-myapp master.com 80 10m [root@master ~]# kubectl describe ingress ingress-myapp ....... [root@master ~]# while true;do curl master.com:30080/hostname.html;sleep 1;done myapp-8w7bm myapp-n4xhs myapp-n4xhs myapp-8w7bm
3、資源獲取(metrics-server)app
1)安裝metrics-server負載均衡
https://github.com/baishuchao/kubernetes/tree/master/metrics-server [root@ks-master k8s]# git clone https://github.com/baishuchao/kubernetes.git [root@ks-master k8s]# cd kubernetes/metrics-server [root@ks-master metrics-server]#kubectl apply -f .
2)資源獲取示例
[root@master dashboard]# kubectl top pods -n kube-system NAME CPU(cores) MEMORY(bytes) coredns-d5947d4b-45r9x 5m 15Mi coredns-d5947d4b-snsjt 6m 15Mi etcd-master 53m 145Mi kube-apiserver-master 83m 276Mi kube-controller-manager-master 23m 54Mi kube-flannel-ds-amd64-x6pcr 2m 16Mi kube-flannel-ds-amd64-xntt5 4m 18Mi kube-flannel-ds-amd64-zsq6r 4m 20Mi kube-proxy-v67qd 12m 20Mi kube-proxy-zg6ws 9m 20Mi kube-proxy-zkmgh 9m 24Mi kube-scheduler-master 2m 18Mi kubernetes-dashboard-b6dcb8878-ckcz5 0m 0Mi metrics-server-7579f696d8-kv8hs 1m 14Mi