您好,登錄后才能下訂單哦!
Kubernetes部署(一):架構及功能說明
Kubernetes部署(二):系統環境初始化
Kubernetes部署(三):CA證書制作
Kubernetes部署(四):ETCD集群部署
Kubernetes部署(五):Haproxy、Keppalived部署
Kubernetes部署(六):Master節點部署
Kubernetes部署(七):Node節點部署
Kubernetes部署(八):Flannel網絡部署
Kubernetes部署(九):CoreDNS、Dashboard、Ingress部署
Kubernetes部署(十):儲存之glusterfs和heketi部署
Kubernetes部署(十一):管理之Helm和Rancher部署
Kubernetes部署(十二):helm部署harbor企業級鏡像倉庫
所有的軟件及配置文件都保存在前面文章提到的百度網盤里 :百度共享鏈接在此文章里
[root@node-01 k8s]# kubectl create -f coredns/coredns.yaml
serviceaccount/coredns created
clusterrole.rbac.authorization.k8s.io/system:coredns created
clusterrolebinding.rbac.authorization.k8s.io/system:coredns created
configmap/coredns created
deployment.extensions/coredns created
service/coredns created
[root@node-01 yaml]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5f94b495b5-58t47 1/1 Running 0 6m
coredns-5f94b495b5-wvcsg 1/1 Running 0 6m
然后我們就可以隨便進入一個pod,去ping域名看dns是否可以正常解析。
[root@node-01 yaml]# kubectl get pod
NAME READY STATUS RESTARTS AGE
tomcat-7666b9764-mfgpb 1/1 Running 0 11h
[root@node-01 yaml]# kubectl exec -it tomcat-7666b9764-mfgpb -- /bin/sh
# ping baidu.com
PING baidu.com (220.181.57.216) 56(84) bytes of data.
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=1 ttl=54 time=37.2 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=2 ttl=54 time=37.0 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=3 ttl=54 time=36.6 ms
64 bytes from 220.181.57.216 (220.181.57.216): icmp_seq=4 ttl=54 time=37.9 ms
^C
--- baidu.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 36.629/37.230/37.958/0.498 ms
[root@node-01 yaml]# kubectl create -f dashboard/
[root@node-01 yaml]# kubectl cluster-info
Kubernetes master is running at https://10.31.90.200:6443
CoreDNS is running at https://10.31.90.200:6443/api/v1/namespaces/kube-system/services/coredns:dns/proxy
kubernetes-dashboard is running at https://10.31.90.200:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
https://10.31.90.200:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
用戶名:admin 密碼:admin 選擇令牌模式登錄。
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk '{print $1}')
操作完以上步驟就可以看到dashboard了。
Kubernetes中,Service資源和Pod資源的IP地址僅能用于集群網絡內部的通信,所有的網絡流量都無法穿透邊界路由器(Edge Router)以實 現集群內外通信。盡管可以為Service使用NodePort或LoadBalancer類型通過節點引入外部流量,但它依然是4層流量轉發,可用的負載均衡器也 為傳輸層負載均衡機制。
可以下載官方的mandatory.yaml
到本地安裝
[root@node-01 ingress]# kubectl create -f mandatory.yaml
或者
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/mandatory.yaml
由于官方的ingress也只是一個pod并沒有對外暴露IP和端口,所以我們需要為ingress創建一個對外暴露的service,暴露nodePort 20080和20443端口。對于想部署在生產環境的,可以單獨拿2個node服務器來單獨部署ingress controller,然后暴露80和443端口就可以了。
apiVersion: v1
kind: Service
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
type: NodePort
ports:
- name: http
nodePort: 20080
port: 80
targetPort: 80
protocol: TCP
- name: https
nodePort: 20443
port: 443
targetPort: 443
protocol: TCP
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
然后在haproxy的backend中加入3個node 的20080和20443端口,不明白我的網絡架構的請看這里,然后將www.cnlinux.club
的A記錄
解析到10.31.90.200
listen ingress-80
bind 10.31.90.200:80
mode tcp
balance roundrobin
timeout server 15s
timeout connect 15s
server apiserver01 10.31.90.204:20080 check port 20080 inter 5000 fall 5
server apiserver02 10.31.90.205:20080 check port 20080 inter 5000 fall 5
server apiserver03 10.31.90.206:20080 check port 20080 inter 5000 fall 5
listen ingress-443
bind 10.31.90.200:443
mode tcp
balance roundrobin
timeout server 15s
timeout connect 15s
server apiserver01 10.31.90.204:20443 check port 20443 inter 5000 fall 5
server apiserver02 10.31.90.205:20443 check port 20443 inter 5000 fall 5
server apiserver03 10.31.90.206:20443 check port 20443 inter 5000 fall 5
[root@node-01 yaml]# kubectl create -f tomcat-demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat
labels:
app: tomcat
spec:
replicas: 1
selector:
matchLabels:
app: tomcat
template:
metadata:
labels:
app: tomcat
spec:
containers:
- name: tomcat
image: tomcat:latest
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: tomcat
spec:
selector:
app: tomcat
ports:
- name: tomcat
protocol: TCP
port: 8080
targetPort: 8080
type: ClusterIP
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tomcat
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: www.cnlinux.club
http:
paths:
- path:
backend:
serviceName: tomcat
servicePort: 8080
至此ingress就已創建完成。在瀏覽器打開www.cnlinux.club 就可以看到tomcat的頁面。
后續會陸續更新所有的k8s相關文檔,如果你覺得我寫的不錯,希望大家多多關注點贊,非常感謝!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。