第十五章 k8s高级篇-中间件容器化机Helm
目录1,容器中间件说明
一切皆容器
# 常用的中间件
rabbitmq
redis
mysql
kafka
MongoDB
2,部署应用至k8s通用步骤
中间件单实例部署
1、找到官方镜像:https://hub.docker.com/
2、确认需要的配置:环境变量或配置文件
3、选择部署方式:Deployment或其他的
4、配置访问:TCP或HTTP
3,部署单实例中间件至k8s
部署单实例rabbitmq
# 创建一个命名空间
[root@k8s-master01 rabbitmq]# kubectl create ns public-service
# rabbitmq的deployment 此处部署的是单实例 所以用了deployment
[root@k8s-master01 rabbitmq]# cat rabbitmq-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: rabbitmq
name: rabbitmq
namespace: public-service
spec:
replicas: 1
selector:
matchLabels:
app: rabbitmq
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: rabbitmq
spec:
affinity: {}
containers:
- env:
- name: TZ
value: Asia/Shanghai
- name: LANG
value: C.UTF-8
- name: RABBITMQ_DEFAULT_USER # 指定rabbitmq的账户
value: admin # 指定rabbitmq的密码
- name: RABBITMQ_DEFAULT_PASS
value: admin
image: registry.cn-beijing.aliyuncs.com/k8s-study-test/rabbitmq:3.8.17-management
imagePullPolicy: Always
lifecycle: {}
livenessProbe:
failureThreshold: 2
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 5672
timeoutSeconds: 2
name: rabbitmq
ports:
- containerPort: 5672
name: web
protocol: TCP
readinessProbe:
failureThreshold: 2
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 5672
timeoutSeconds: 2
resources:
limits:
cpu: 935m
memory: 1Gi
requests:
cpu: 97m
memory: 512Mi
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
status: {}
# rabbitmq的service
[root@k8s-master01 rabbitmq]# cat rabbitmq-svc.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: rabbitmq
name: rabbitmq
namespace: public-service
spec:
ports:
- name: web
port: 5672
protocol: TCP
targetPort: 5672
- name: http
port: 15672
protocol: TCP
targetPort: 15672
selector:
app: rabbitmq
sessionAffinity: None
type: NodePort
# 查询
[root@k8s-master01 rabbitmq]# kubectl get pod -n public-service
NAME READY STATUS RESTARTS AGE
rabbitmq-d89c56c8-44nn2 1/1 Running 0 46m
[root@k8s-master01 rabbitmq]# kubectl get svc -n public-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
rabbitmq NodePort 10.108.113.69 <none> 5672:32545/TCP,15672:32005/TCP 61m
注:
rabbitmq的 默认用户密码是guest和guest,我们在deploy中的env中可以指定
- name: RABBITMQ_DEFAULT_USER # 指定rabbitmq的账户
value: admin
- name: RABBITMQ_DEFAULT_PASS # 指定rabbitmq的密码
value: admin
- 在生产或测试环境,rabbitmq重启后数据会丢失的,我们需要配置数据挂载目录将数据存储起来
4,k8s中间件的访问模式
1. 通过http访问rabbitmq提供的web界面
我们此处是通过service的NodePort来访问的
http://192.168.0.118:32005
不出意外会出现如下界面
我们输入刚才设置的账号密码登录(admin/admin)
2. 开发用
集群内访问rabbitmq:5672 # <service_name>:<port>
集群外访问192.168.0.117:32545 # <宿主机的IP地址>:<NodePort端口号>
标签:name,service,中间件,rabbitmq,5672,Helm,化机,k8s
From: https://www.cnblogs.com/wangerrui/p/16920347.html