搭建Discuz
链接:https://gitee.com/3dming/DiscuzL/attach_files 要求:ingress —> headless service —> pod 1、要有健康检查 2、要求有https 3、要求有存储卷,数据持久化,防止容器停止或宕机数据随之丢失 (hostpath:类似于docker -v参数,将存储卷挂载在本地【pod部署的节点上】)
[root@k8s-master1 discuz]
总用量 12044
-rw-r--r-- 1 root root 12330468 4月 7 2021 Discuz_X3.4_SC_UTF8_20210320.zip
[root@k8s-master1 discuz]
[root@k8s-master1 discuz]
总用量 12172
-rw-r--r-- 1 root root 12330468 4月 7 2021 Discuz_X3.4_SC_UTF8_20210320.zip
-rw-r--r-- 1 root root 17886 3月 20 10:36 LICENSE
-rw-r--r-- 1 root root 31040 1月 19 17:18 qqqun.png
drwxr-xr-x 2 root root 124 3月 22 19:44 readme
-rw-r--r-- 1 root root 71107 1月 19 17:20 readme.html
drwxr-xr-x 13 root root 4096 3月 22 19:44 upload
drwxr-xr-x 4 root root 94 3月 22 19:44 utility
[root@k8s-master1 discuz]
[root@k8s-master1 discuz]
总用量 22260
-rw-r--r-- 1 root root 10329409 4月 4 01:42 discuz.tar.gz
[root@k8s-master1 discuz]
> ssh root@$i "mkdir -pv /opt/discuz" && scp discuz.tar.gz root@$i:/opt/discuz/
> ssh root@$i "cd /opt/discuz && tar -xf discuz.tar.gz -C /opt/discuz"
> done
mkdir: 已创建目录 "/opt/discuz"
discuz.tar.gz 100% 10MB 48.9MB/s 00:00
ssh: Could not resolve hostname n2: Name or service not known
ssh: Could not resolve hostname n2: Name or service not known
[root@k8s-master1 discuz]
[root@k8s-master1 discuz]
drwxr-xrwx 13 root root 4096 3月 22 19:44 upload
1.部署MySQL集群
命名空间
service提供负载均衡
使用控制器部署MySQL实例
2.部署discuz应用
创建命名空间
创建service提供负载均衡(headless service)
创建ingress,用于域名转发
3.服务之间的互连
discuz连接MySQL===》mysql.mysql.svc.cluster.local
==============================================================================
[root@k8s-master1 discuz]
Generating RSA private key, 2048 bit long modulus
.+++
........................................................................+++
e is 65537 (0x10001)
[root@k8s-master1 discuz]
[root@k8s-master1 discuz]
namespace/discuz created
[root@k8s-master1 discuz]
secret/discuz-secret created
[root@k8s-master1 discuz]
-rw-r--r-- 1 root root 1334 4月 4 03:50 tls.crt
-rw-r--r-- 1 root root 1675 4月 4 03:49 tls.key
[root@k8s-master1 discuz]
apiVersion: v1
kind: Namespace
metadata:
name: mysql
---
apiVersion: v1
kind: Service
metadata:
name: mysql-svc
namespace: mysql
spec:
ports:
- port: 3306
targetPort: 3306
name: mysql
protocol: TCP
selector:
app: mysql
deploy: discuz
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
namespace: mysql
spec:
selector:
matchLabels:
app: mysql
deploy: discuz
template:
metadata:
labels:
app: mysql
deploy: discuz
spec:
nodeName: gdx3
containers:
- name: mysql
image: mysql:5.7
livenessProbe:
tcpSocket:
port: 3306
readinessProbe:
tcpSocket:
port: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123456"
- name: MYSQL_DATABASE
value: "discuz"
volumeMounts:
- mountPath: /var/lib/mysql
name: mysql-data
volumes:
- name: mysql-data
hostPath:
path: /opt/discuz/mysql
---
apiVersion: v1
kind: Namespace
metadata:
name: discuz
---
apiVersion: v1
kind: Service
metadata:
name: discuz-svc
namespace: discuz
spec:
clusterIP: None
ports:
- port: 80
targetPort: 80
name: http
selector:
app: discuz
deploy: discuz
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: discuz-deployment
namespace: discuz
spec:
selector:
matchLabels:
app: discuz
deploy: discuz
template:
metadata:
labels:
app: discuz
deploy: discuz
spec:
nodeName: gdx3
containers:
- name: php
image: elaina0808/lnmp-php:v6
livenessProbe:
tcpSocket:
port: 9000
readinessProbe:
tcpSocket:
port: 9000
volumeMounts:
- mountPath: /usr/share/nginx/html
name: discuz-data
- name: nginx
image: elaina0808/lnmp-nginx:v9
livenessProbe:
httpGet:
port: 80
path: /
readinessProbe:
httpGet:
port: 80
path: /
volumeMounts:
- mountPath: /usr/share/nginx/html
name: discuz-data
volumes:
- name: discuz-data
hostPath:
path: /opt/discuz/upload
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: discuz-ingress
namespace: discuz
spec:
tls:
- hosts:
- www.discuz.cluster.local.com
secretName: discuz-secret
rules:
- host: www.discuz.cluster.local.com
http:
paths:
- backend:
serviceName: discuz-svc
servicePort: 80
[root@k8s-master1 discuz]
NAME READY STATUS RESTARTS AGE
discuz-deployment-cbbbfc54b-l22wq 2/2 Running 0 58m
[root@k8s-master1 discuz]
NAME READY STATUS RESTARTS AGE
mysql-deployment-c687787fc-l7n5s 1/1 Running 0 118m
[root@k8s-master1 discuz]
NAME CLASS HOSTS ADDRESS PORTS AGE
discuz-ingress <none> www.discuz.cluster.local.com 192.168.12.12 80, 443 121m
[root@k8s-master1 discuz]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
ingress-nginx-controller NodePort 10.96.60.88 <none> 80:32708/TCP,443:32731/TCP 36h
ingress-nginx-controller-admission ClusterIP 10.106.141.57 <none> 443/TCP 36h
192.168.12.11 www.discuz.cluster.local.com
注意:如果没有kubectl get svc -n ingress-nginx 查不到端口,这时候就需要把deploy.yaml文件放在对应的文件启动
wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.44.0/deploy/static/provider/baremetal/deploy.yaml --no-check-certificat
sed -i 's#k8s.gcr.io/ingress-nginx/controller:v0.44.0@sha256:3dd0fac48073beaca2d67a78c746c7593f9c575168a17139a9955a82c63c4b9a#registry.cn-hangzhou.aliyuncs.com/k8sos/ingress-controller:v0.44.0#g' deploy.yaml
kubectl apply -f deploy.yaml
创建自定义ingress报错:Internal error occurred: failed calling webhook “validate.nginx.ingress.kubernetes.io
报错:
Internal error occurred: failed calling webhook "validate.nginx.ingress.kubernetes.io": Post
https://ingress-nginx-controller-admission.kube-system.svc:443/networking/v1beta1/ingresses?
timeout=10s: dial tcp 10.0.0.5:8443: connect: connection refused
原因分析:
我刚开始使用yaml的方式创建nginx-ingress,之后删除了它创建的命名空间以及 clusterrole and clusterrolebinding ,但是没有删除ValidatingWebhookConfiguration ingress-nginx-admission,这个ingress-nginx-admission是在yaml文件中安装的。当我再次使用helm安装nginx-ingress之后,创建自定义的ingress就会报这个错误。
解决方案:
使用下面的命令查看 webhook
kubectl get validatingwebhookconfigurations
出来这个
ingress-nginx-admission
删除ingress-nginx-admission
kubectl delete -A ValidatingWebhookConfiguration ingress-nginx-admission
|