In centos7 build kubernetes1.16.7 cluster I , the built environment follows progress
k8s-master :192.168.1.127
k8s-node1 :192.168.1.122
k8s-node2 :192.168.1.132
This will build ingress, and do the test mediawiki.
Pull mediawiki
# Each node must pull
docker pull mufengziyu / mediawiki: 1.18.0
Download Ingress related yaml
# Download Ingress used to create documents related yaml
ingress- nginx for File in namespace.yaml configmap.yaml rbac.yaml configmap.yaml tcp-Services-Services-with-rbac.yaml udp-configmap.yaml default - backend.yaml; do wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/nginx-0.17.0/deploy/ $ File ; DONE
Download yaml modified accordingly
Modify yaml
# 修改 with-rbac.yaml # 如下,在serviceAccountName上方添加hostNetwork: true: spec: hostNetwork: true serviceAccountName: nginx-ingress-serviceaccount containers: - name: nginx-ingress-controller image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.14.0 args: - /nginx-ingress-controller - --default-backend-service=$(POD_NAMESPACE)/default-http-backend - --configmap=$(POD_NAMESPACE)/nginx-configuration - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services - --udp-services-configmap=$(POD_NAMESPACE)/udp-services - --annotations-prefix=nginx.ingress.kubernetes.io
# Modify-rbac.yaml with # were added as part of the environment variable in its env env: - name: POD_NAME the valueFrom: fieldRef: The fieldPath: metadata.name - name: POD_NAMESPACE the valueFrom: fieldRef: The fieldPath: metadata.namespace - name: KUBERNETES_MASTER value: HTTP: //192.168.56.101:8080
Creating Ingress-controller
ingress-nginx for file in namespace.yaml configmap.yaml rbac.yaml tcp-services-configmap.yaml with-rbac.yaml udp-services-configmap.yaml default-backend.yaml; do kubectl apply -f $file; done
After you create a View pod
[root@k8s-node1 ~]# kubectl get pod -n ingress-nginx -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES default-http-backend-7b7fd455bd-ptsrt 1/1 Running 3 39h 10.244.1.7 k8s-node1 <none> <none> nginx-ingress-controller-657bbdc77-l4jps 1/1 Running 5 39h 192.168.1.122 k8s-node1 <none> <none>
Create a custom Ingress
# 创建 deployment , service
[root@k8s-master ~]# vi yaml/media.yaml [root@k8s-master ~]# cat yaml/media.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: mediawiki-pod name: mediawiki-pod spec: replicas: 1 selector: matchLabels: app: mediawiki-pod template: metadata: labels: app: mediawiki-pod spec: containers: - image: mufengziyu/mediawiki:1.18.0 name: mediawiki-pod ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: mediawiki-pod-service labels: app: mediawiki-pod # 对应pod得label spec: type: NodePort # 类型ExternalName, ClusterIP, NodePort, and LoadBalancer ports: - port: 80 targetPort: 80 nodePort: 30002 # 端口范围【30000-32767】 selector: app: mediawiki -POD
[root@k8s-master ~] kubectl apply -f media.yaml
# Creating Ingress # Host: the domain ingress-controller where the node is not ip # establish a local DNS service to # serviceName and servicePort correspond to service the Name and Port [root @ K8S-Master ~] # vi YAML / MEDIA- ingress.yaml [K8S the root-Master @ ~] # CAT YAML / Media-ingress.yaml apiVersion: Extensions / v1beta1 kind: the Ingress Metadata: name: MediaWiki - Ingress namespace: default spec: the rules: - Host: k8s- node1.com HTTP: Paths: - path: / backend: serviceName: MediaWiki -pod- Service servicePort: 80 [root@k8s-master ~]# kubectl apply -f media-ingress.yaml
# Modify local service dsn
# to open the / etc / host, insert ip domain name mapping # I add the following 192.168.1.122 k8s- node1.com 192.168.1.127 k8s- master.com 192.168.1.132 k8s-node2.com
View Results
[root@k8s-master ~]# kubectl get pod --all-namespaces NAMESPACE NAME READY STATUS RESTARTS AGE default mediawiki-pod-74c76684d-z9ss5 1/1 Running 1 16h ingress-nginx default-http-backend-7b7fd455bd-ptsrt 1/1 Running 3 39h ingress-nginx nginx-ingress-controller-657bbdc77-l4jps 1/1 Running 5 39h kube-system coredns-58cc8c89f4-955zb 1/1 Running 12 2d19h kube-system coredns-58cc8c89f4-bp746 1/1 Running 12 2d19h kube-system etcd-k8s-master 1/1 Running 5 2d19h kube-system kube-apiserver-k8s-master 1/1 Running 5 2d19h kube-system kube-controller-manager-k8s-master 1/1 Running 5 2d19h kube-system kube-flannel-ds-amd64-5f28r 1/1 Running 3 41h kube-system kube-flannel-ds-amd64-9s6v2 1/1 Running 4 41h kube-system kube-flannel-ds-amd64-fvrmj 1/1 Running 5 2d19h kube-system kube-proxy-cddqh 1/1 Running 4 41h kube-system kube-proxy-d8sxd 1/1 Running 5 2d19h kube-system kube-proxy-gfvhf 1/1 Running 3 41h kube-system kube-scheduler-k8s-master 1/1 Running 5 2d19h [root@k8s-master ~]# kubectl get deployment NAME READY UP-TO-DATE AVAILABLE AGE mediawiki-pod 1/1 1 1 16h [root@k8s-master ~]# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d19h mediawiki-pod-service NodePort 10.98.86.108 <none> 80:30002/TCP 16h [root@k8s-master ~]# kubectl get ingress NAME HOSTS ADDRESS PORTS AGE mediawiki-ingress k8s-node1.com 80 15h
# 访问 服务 # 未添加数据库,所以显示 这个页面 [root@k8s-master ~]# curl k8s-node1.com <h1>Sorry! This site is experiencing technical difficulties.</h1><p>Try waiting a few minutes and reloading.</p><p><small>(Can't contact the database server: <span dir="ltr">No route to host (192.168.1.200)</span>)</small></p><hr /><div style="margin: 1.5em">You can try searching via Google in the meantime.<br /> <small>Note that their indexes of our content may be out of date.</small></div> <!-- SiteSearch Google --> <form method="get" action="http://www.google.com/search" id="googlesearch"> <input type="hidden" name="domains" value="" /> <input type="hidden" name="num" value="50" /> <input type="hidden" name="ie" value="UTF-8" /> <input type="hidden" name="oe" value="UTF-8" /> <input type="text" name="q" size="31" maxlength="255" value="" /> <input type="submit" name="btnG" value="Search" /> <div> <input type="radio" name="sitesearch" id="gwiki" value="" checked="checked" /><label for="gwiki">test</label> <input type="radio" name="sitesearch" id="gWWW" value="" /><label for="gWWW">WWW</label> </div> </form>
If using windows to access, modify C: \ Windows \ System32 \ drivers \ etc \ hosts file, add the appropriate domain name mapping ip
Test Results