当前位置: 代码迷 >> 综合 >> Hands-on Lab (11) - 部署StatefulSets应用
  详细解决方案

Hands-on Lab (11) - 部署StatefulSets应用

热度:37   发布时间:2024-02-27 17:01:59.0
  1. 创建项目
$ oc new-project my-rocket
  1. 创建内容如下的mongodb-internal.yaml文件。
kind: Service
apiVersion: v1
metadata:name: "mongodb-internal"labels:name: "mongodb"annotations:service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:clusterIP: Noneports:- name: mongodbport: 27017selector:name: "mongodb"
  1. 创建内容如下的mongodb.yaml文件。
kind: Service
apiVersion: v1
metadata:name: "mongodb"labels:name: "mongodb"
spec:ports:- name: mongodbport: 27017selector:name: "mongodb"
  1. 创建内容如下的mongodb-statefulset.yaml文件。
kind: StatefulSet
apiVersion: apps/v1
metadata:name: "mongodb"
spec:serviceName: "mongodb-internal"replicas: 3selector:matchLabels:name: mongodbtemplate:metadata:labels:name: "mongodb"spec:containers:- name: mongo-containerimage: "registry.access.redhat.com/rhscl/mongodb-36-rhel7:latest"ports:- containerPort: 27017args:- "run-mongod-replication"volumeMounts:- name: mongo-datamountPath: "/var/lib/mongodb/data"env:- name: MONGODB_DATABASEvalue: "mongodb"- name: MONGODB_USERvalue: "mongodb_user"- name: MONGODB_PASSWORDvalue: "mongodb_password"- name: MONGODB_ADMIN_PASSWORDvalue: "mongodb_admin_password"- name: MONGODB_REPLICA_NAMEvalue: "rs0"- name: MONGODB_KEYFILE_VALUEvalue: "12345678901234567890"- name: MONGODB_SERVICE_NAMEvalue: "mongodb-internal"readinessProbe:exec:command:- stat- /tmp/initializedvolumeClaimTemplates:- metadata:name: mongo-datalabels:name: "mongodb"spec:accessModes: [ ReadWriteOnce ]resources:requests:storage: "4Gi"
  1. 执行命令,根据以上3个文件创建相关资源。
$ oc create -f mongodb.yaml
$ oc create -f mongodb-internal.yaml
$ oc create -f mongodb-statefulset.yaml
  1. 查看pvc,然后将名为mongodb的statefulset扩展到3个。
$ oc get pvc
$ oc scale statefulset mongodb --replicas=3
  1. 执行命令,部署应用客户端。
$ oc new-app docker.io/rocketchat/rocket.chat:0.63.3 -e MONGO_URL="mongodb://mongodb_user:mongodb_password@mongodb:27017/mongodb?replicaSet=rs0" --as-deployment-config=true
$ oc expose svc/rocketchat
  1. 查看rocketchat应用对应的route访问地址。
$ oc get route rocketchat   
NAME         HOST/PORT                                                       PATH   SERVICES     PORT       TERMINATION   WILDCARD
rocketchat   rocketchat-0b56-rocket.apps.cluster-sten.sten.ilt.opentlc.com          rocketchat   3000-tcp                 None
  1. 然后用浏览器打开访问。在注册并登陆后,将显示以下应用界面。
    在这里插入图片描述
  相关解决方案