6 k8s-mongodb集群部署(副本集)
<h4 class="md-end-block md-heading md-focus" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n0"><span class="md-plain md-expand" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">1 环境说明</font></span></h4><figure class="md-table-fig" style="margin: 17px 0; padding: 0; text-transform: none; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: normal; cursor: default; -ms-overflow-x: auto; max-width: calc(100% + 16px); box-sizing: border-box; orphans: 2; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="table" cid="n2"><table width="930" class="md-table" style="margin: 0; padding: 0; text-align: left; overflow: auto; white-space: pre-wrap; border-collapse: collapse; cursor: text; box-sizing: border-box; border-spacing: 0; break-inside: auto">
<thead style="display: table-header-group; box-sizing: border-box; background-color: rgba(248, 248, 248, 1)">
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n3">
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n4"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">主机名</font></span></span></th>
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n5"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">系统版本</font></span></span></th>
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n6"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">IP地址</font></span></span></th>
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n7"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">cpu/内存/磁盘</font></span></span></th>
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n8"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">用途</font></span></span></th>
<th style="border-top: 1px solid rgba(223, 223, 223, 1); border-right: 1px solid rgba(223, 223, 223, 1); border-bottom: 2px solid rgba(204, 204, 204, 1); border-left: 1px solid rgba(223, 223, 223, 1); margin: 0; padding: 10px 16px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n9"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">软件版本</font></span></span></th></tr></thead>
<tbody style="box-sizing: border-box">
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n10">
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n11"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s_nfs</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n12"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">CentOS7.5</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n13"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">172.16.1.60</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n14"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">2核/2GB/60GB</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n15"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">nfs存储</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n16"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">nfs-utils-1.3.0-0.68</font></span></span></td></tr>
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n17">
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n18"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s-master1</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n19"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">CentOS7.5</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n20"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">172.16.1.81</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n21"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">2核/4GB/60GB</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n22"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">kubernetes master1节点</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n23"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s v1.20.0</font></span></span></td></tr>
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n24">
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n25"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s-master2</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n26"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">CentOS7.5</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n27"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">172.16.1.82</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n28"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">2核/4GB/60GB</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n29"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">kubernetes master2节点</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n30"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s v1.20.0</font></span></span></td></tr>
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n31">
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n32"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s-node1</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n33"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">CentOS7.5</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n34"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">172.16.1.83</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n35"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">4核/8GB/60GB</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n36"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">kubernetes node1节点</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n37"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s v1.20.0</font></span></span></td></tr>
<tr class="md-end-block" style="margin: 0; padding: 0; border-top: 1px solid rgba(223, 223, 223, 1); box-sizing: border-box; break-after: auto; break-inside: avoid" mdtype="table_row" cid="n38">
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 99.75px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n39"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s-node2</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 86.21px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n40"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">CentOS7.5</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 95.32px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n41"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">172.16.1.84</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 118.18px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n42"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">4核/8GB/60GB</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 187.06px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n43"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">kubernetes node2节点</font></span></span></td>
<td style="margin: 0; padding: 10px 16px; border: 1px solid rgba(223, 226, 229, 1); border-image: none; min-width: 32px; box-sizing: border-box"><span class="td-span" style="width: 144.46px; display: inline-block; min-height: 10px; min-width: 1ch; box-sizing: border-box" mdtype="table_cell" cid="n44"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 10.5pt">k8s v1.20.0</font></span></span></td></tr></tbody></table></figure>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n45"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">补充: kubernetes集群的控制节点我打了污点不能被pod调度使用。</font></code></span></p>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n46"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt">1 nfs服务部署</font></span><font style="font-size: 10.8pt"><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">节点: k8s_nfs</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">用途: k8s pod 数据持久化存储</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">说明: nfs服务的搭建过程不再赘述</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">验证:</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"># showmount -e 172.16.1.60</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">Export list for 172.16.1.60:</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">/ifs/kubernetes *</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><span style="box-sizing: border-box" cm-zwsp="" cm-text=""></span></span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">2 nfs-subdir-external-provisioner插件部署</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">节点: kubernetes集群</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">用途: 为中间件pod提供pvc自动供给</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">说明: nfs pvc自动供给插件的部署过程不再赘述。修改"deployment.yaml"文件中连接nfs服务的地址和nfs共享目录参数;修改"class.yaml"</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">文件中"archiveOnDelete"(删除时是否存档)参数为 archiveOnDelete: "true",删除pod时保留pod数据,默认为false时为不保留数据。</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">注意: 在部署前需要在k8s各个节点上部署nfs的客户端(yum install nfs-utils -y),否则无法部署成功。</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><span style="box-sizing: border-box" cm-zwsp="" cm-text=""></span></span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">补充:</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">(1) gitlab项目地址: https://github.com/kubernetes-sigs/nfs-subdir-external-provisioner</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">(2) 下载 deploy 目录如下文件</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">class.yaml、deployment.yaml、rbac.yaml</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><span style="box-sizing: border-box" cm-zwsp="" cm-text=""></span></span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">查看:</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"># ls | xargs -i kubectl apply -f {}</span><br></font><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl get deployment,pod,svc,sc -n default</font></span></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n47"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220214160856064.png"><img width="1289" height="222" title="image-20220214160856064" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220214160856064" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114918806-1382526623.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h4 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n48"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">2 mongodb集群部署(副本集)</font></span></h4>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n49"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">2.1 创建mongodb-cluster命名空间</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n50"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># mkdir -p mongodb-cluster/</font></span><font style="font-size: 10.8pt"><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"># cd mongodb-cluster/</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><span style="box-sizing: border-box" cm-zwsp="" cm-text=""></span></span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"># kubectl create namespace mongodb-cluster</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">namespace/mongodb-cluster created</span><br></font><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># </font></span></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n51"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">2.2 从秘钥文件创建secret</font></span></h5>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n52"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">秘钥文件用于mongodb副本集之间进行数据复制时免密码,MongoDB将使用此密钥与内部集群通信。</font></code></span><font style="font-size: 8.9pt"><span class="md-softbreak" style="box-sizing: border-box" md-inline="softbreak">
</span></font><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">kubectl create secret generic: 表示根据配置文件、目录或指定的literal-value创建secret。</font></code></span></p>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n53"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># openssl rand -base64 741 > ./key.txt</font></span><font style="font-size: 10.8pt"><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><span style="box-sizing: border-box" cm-zwsp="" cm-text=""></span></span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"># kubectl create secret generic mongodb-replica-sets-key -n mongodb-cluster \</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">--from-file=internal-auth-mongodb-keyfile=./key.txt</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">secret/mongodb-replica-sets-key created</span><br></font><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># </font></span></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n54"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">2.3 mongodb-statefulset.yaml</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n55"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"><div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)"><pre># <span style="color: rgba(0, 0, 255, 1)">cat</span> mongodb-<span style="color: rgba(0, 0, 0, 1)">statefulset.yaml
apiVersion: v1
kind: Service
metadata:
name: mongodb</span>-<span style="color: rgba(0, 0, 0, 1)">cluster
namespace: mongodb</span>-<span style="color: rgba(0, 0, 0, 1)">cluster
labels:
name: mongo
spec:
ports:
</span>- port: <span style="color: rgba(128, 0, 128, 1)">27017</span><span style="color: rgba(0, 0, 0, 1)">
targetPort: </span><span style="color: rgba(128, 0, 128, 1)">27017</span><span style="color: rgba(0, 0, 0, 1)">
clusterIP: None
selector:
role: mongo
</span>---<span style="color: rgba(0, 0, 0, 1)">
apiVersion: apps</span>/<span style="color: rgba(0, 0, 0, 1)">v1
kind: StatefulSet
metadata:
name: mongodb</span>-<span style="color: rgba(0, 0, 0, 1)">cluster
namespace: mongodb</span>-<span style="color: rgba(0, 0, 0, 1)">cluster
spec:
serviceName: mongodb</span>-<span style="color: rgba(0, 0, 0, 1)">cluster
replicas: </span><span style="color: rgba(128, 0, 128, 1)">3</span><span style="color: rgba(0, 0, 0, 1)">
selector:
matchLabels:
role: mongo
environment: produce
replicaset: MainRepSet
template:
metadata:
labels:
role: mongo
environment: produce
replicaset: MainRepSet
spec:
containers:
</span>- name: mongodb-<span style="color: rgba(0, 0, 0, 1)">container
image: registry.cn</span>-hangzhou.aliyuncs.com/k8s-image01/mongodb:<span style="color: rgba(128, 0, 128, 1)">4.2</span>.<span style="color: rgba(128, 0, 128, 1)">21</span>-<span style="color: rgba(0, 0, 0, 1)">bionic
command:
</span>- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">numactl</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--interleave=all</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">mongod</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--bind_ip</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">0.0.0.0</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--replSet</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">MainRepSet</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--auth</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--clusterAuthMode</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">keyFile</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--keyFile</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">/etc/secrets-volume/internal-auth-mongodb-keyfile</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">--setParameter</span><span style="color: rgba(128, 0, 0, 1)">"</span>
- <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">authenticationMechanisms=SCRAM-SHA-1</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
resources:
requests:
cpu: </span><span style="color: rgba(128, 0, 128, 1)">0.5</span><span style="color: rgba(0, 0, 0, 1)">
memory: 500Mi
ports:
</span>- containerPort: <span style="color: rgba(128, 0, 128, 1)">27017</span><span style="color: rgba(0, 0, 0, 1)">
volumeMounts:
</span>- name: secrets-<span style="color: rgba(0, 0, 0, 1)">volume
readOnly: </span><span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)">
mountPath: </span>/etc/secrets-<span style="color: rgba(0, 0, 0, 1)">volume
</span>- name: mongodb-persistent-storage-<span style="color: rgba(0, 0, 0, 1)">claim
mountPath: </span>/data/<span style="color: rgba(0, 0, 0, 1)">db
volumes:
</span>- name: secrets-<span style="color: rgba(0, 0, 0, 1)">volume
secret:
secretName: mongodb</span>-replica-sets-<span style="color: rgba(0, 0, 0, 1)">key
defaultMode: </span><span style="color: rgba(128, 0, 128, 1)">256</span><span style="color: rgba(0, 0, 0, 1)">
volumeClaimTemplates:
</span>-<span style="color: rgba(0, 0, 0, 1)"> metadata:
name: mongodb</span>-persistent-storage-<span style="color: rgba(0, 0, 0, 1)">claim
#annotations:
#volume.beta.kubernetes.io</span>/storage-class: <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">standard</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
spec:
storageClassName: </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">managed-nfs-storage</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
accessModes: [ </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">ReadWriteOnce</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> ]
resources:
requests:
storage: 10Gi</span></pre></div><br></font></span></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n56"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">2.4 应用yaml文件</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n57"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl apply -f mongodb-statefulset.yaml</font></span><font style="font-size: 10.8pt"><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">service/mongodb-cluster created</span><br><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box">statefulset.apps/mongodb-cluster created</span><br></font><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># </font></span></pre>
<h4 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n58"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">3 查看mongodb集群</font></span></h4>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n59"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.1 查看pod</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n60"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl get statefulset/mongodb-cluster -n mongodb-cluster -o wide</font></span><font style="font-size: 10.8pt"><br></font><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl get pod -n mongodb-cluster -o wide</font></span></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n61"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220625161822074.png"><img width="962" height="173" title="image-20220625161822074" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220625161822074" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114919781-237280882.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n62"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.2 查看pvc</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n63"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl get pvc -n mongodb-cluster -o wide</font></span></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n64"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220625161911224.png"><img width="1365" height="106" title="image-20220625161911224" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220625161911224" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114920723-598717810.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n65"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.3 查看pv</font></span></h5>
<pre class="md-fences md-end-block ty-contain-cm modeLoaded" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: normal; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n66"><span role="presentation" style="padding-right: 0.1px; box-sizing: border-box"><font style="font-size: 10.8pt"># kubectl get pv -o wide</font></span></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n67"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220625161943277.png"><img width="1700" height="105" title="image-20220625161943277" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220625161943277" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114921675-489309053.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n68"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.4 查看nfs存储路径</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n69"><font style="font-size: 10.8pt"># ls -l /ifs/kubernetes/</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n70"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220625162010011.png"><img width="1196" height="106" title="image-20220625162010011" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220625162010011" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114922600-1458314845.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n71"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.5 查看svc相关信息</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n72"><font style="font-size: 10.8pt"># kubectl get svc/mongodb-cluster -n mongodb-cluster -o wide<br style="box-sizing: border-box"># kubectl get ep/mongodb-cluster -n mongodb-cluster -o wide</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n73"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220625162050150.png"><img width="965" height="141" title="image-20220625162050150" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220625162050150" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114923585-948303018.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n74"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">3.6 查看mongodb域名解析</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n75"><font style="font-size: 10.8pt"># kubectl run -i --tty --image busybox:1.28.4 dns-test --restart=Never --rm /bin/sh<br style="box-sizing: border-box">If you don't see a command prompt, try pressing enter.<br style="box-sizing: border-box">/ # nslookup mongodb-cluster.mongodb-cluster.svc.cluster.local<br style="box-sizing: border-box">Server: 172.28.0.2<br style="box-sizing: border-box">Address 1: 172.28.0.2 kube-dns.kube-system.svc.cluster.local<br style="box-sizing: border-box"><br style="box-sizing: border-box">Name: mongodb-cluster.mongodb-cluster.svc.cluster.local<br style="box-sizing: border-box">Address 1: 172.27.169.165 mongodb-cluster-1.mongodb-cluster.mongodb-cluster.svc.cluster.local<br style="box-sizing: border-box">Address 2: 172.27.169.166 mongodb-cluster-2.mongodb-cluster.mongodb-cluster.svc.cluster.local<br style="box-sizing: border-box">Address 3: 172.27.36.97 mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local<br style="box-sizing: border-box">/ # exit</font></pre>
<h4 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n76"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">4 mongodb复制集配置</font></span></h4>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n77"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">4.1 初始化mongodb复制集集群</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n78"><font style="font-size: 10.8pt">我们需要连接到"mongodb"容器进程之一来配置副本集,运行以下命令以连接到第一个容器,在shell中启动副本集,由于使用了StatefulSet,我们<br style="box-sizing: border-box">可以依赖主机名始终相同。<br style="box-sizing: border-box"><br style="box-sizing: border-box"># kubectl exec -it pod/mongodb-cluster-0 -n mongodb-cluster -- bash<br style="box-sizing: border-box">root@mongodb-cluster-0:/# mongo<br style="box-sizing: border-box">MongoDB shell version v4.2.21<br style="box-sizing: border-box">connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br style="box-sizing: border-box">Implicit session: session { "id" : UUID("cf61cdba-55f9-4720-8c82-d9f2ab2cf6cd") }<br style="box-sizing: border-box">MongoDB server version: 4.2.21<br style="box-sizing: border-box">Welcome to the MongoDB shell.<br style="box-sizing: border-box">For interactive help, type "help".<br style="box-sizing: border-box">For more comprehensive documentation, see<br style="box-sizing: border-box"> https://docs.mongodb.com/<br style="box-sizing: border-box">Questions? Try the MongoDB Developer Community Forums<br style="box-sizing: border-box"> https://community.mongodb.com<br style="box-sizing: border-box">> use admin<br style="box-sizing: border-box">switched to db admin<br style="box-sizing: border-box">> <br style="box-sizing: border-box">rs.initiate({_id: "MainRepSet", version: 1, members: [<br style="box-sizing: border-box"> { _id: 0, host : "mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local:27017" },<br style="box-sizing: border-box"> { _id: 1, host : "mongodb-cluster-1.mongodb-cluster.mongodb-cluster.svc.cluster.local:27017" },<br style="box-sizing: border-box"> { _id: 2, host : "mongodb-cluster-2.mongodb-cluster.mongodb-cluster.svc.cluster.local:27017" }<br style="box-sizing: border-box">]});<br style="box-sizing: border-box">{ "ok" : 1 }<br style="box-sizing: border-box">MainRepSet:SECONDARY> <br style="box-sizing: border-box">MainRepSet:PRIMARY> </font></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n79"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">4.2 检查mongodb副本集的状态</font></span></h5>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n80"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">检查mongodb副本集的状态,直到mongodb副本集完全初始化并且存在一个主副本和两个辅助副本</font></code></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n81"><font style="font-size: 10.8pt">MainRepSet:PRIMARY> rs.status();</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n82"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">mongodb-cluster-0角色变为PRIMARY,mongodb-cluster-1、mongodb-cluster-2角色变为SECONDARY。</font></code></span></p>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n83"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220626224401650.png"><img width="1276" height="3111" title="image-20220626224401650" style="margin: 0; border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220626224401650" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114924603-1902307837.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n84"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">4.3 配置"admin"用户</font></span></h5>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n85"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">执行此操作会导致"mongodb匿名登录"被自动永久禁用</font></code></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n86"><font style="font-size: 10.8pt">MainRepSet:PRIMARY> <br style="box-sizing: border-box">db.getSiblingDB("admin").createUser({<br style="box-sizing: border-box"> user : "root",<br style="box-sizing: border-box"> pwd: "liuchang123456",<br style="box-sizing: border-box"> roles: [ { role: "root", db: "admin" } ]<br style="box-sizing: border-box">});<br style="box-sizing: border-box"><br style="box-sizing: border-box">Successfully added user: {<br style="box-sizing: border-box"> "user" : "root",<br style="box-sizing: border-box"> "roles" : [<br style="box-sizing: border-box"> {<br style="box-sizing: border-box"> "role" : "root",<br style="box-sizing: border-box"> "db" : "admin"<br style="box-sizing: border-box"> }<br style="box-sizing: border-box"> ]<br style="box-sizing: border-box">}<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> rs.status();<br style="box-sizing: border-box">{<br style="box-sizing: border-box"> "operationTime" : Timestamp(1656255867, 4),<br style="box-sizing: border-box"> "ok" : 0,<br style="box-sizing: border-box"> "errmsg" : "command replSetGetStatus requires authentication",<br style="box-sizing: border-box"> "code" : 13,<br style="box-sizing: border-box"> "codeName" : "Unauthorized",<br style="box-sizing: border-box"> "$clusterTime" : {<br style="box-sizing: border-box"> "clusterTime" : Timestamp(1656255951, 1),<br style="box-sizing: border-box"> "signature" : {<br style="box-sizing: border-box"> "hash" : BinData(0,"hjfd5q6urr0hk0ldnWwQzliMAIE="),<br style="box-sizing: border-box"> "keyId" : NumberLong("7113556038019710977")<br style="box-sizing: border-box"> }<br style="box-sizing: border-box"> }<br style="box-sizing: border-box">}<br style="box-sizing: border-box">MainRepSet:PRIMARY> exit</font></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n87"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">4.4 验证登录mongodb副本集</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n88"><font style="font-size: 10.8pt">root@mongodb-cluster-0:/# mongo --host mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local \<br style="box-sizing: border-box">--port 27017 -uroot -p'liuchang123456' admin<br style="box-sizing: border-box">MongoDB shell version v4.2.21<br style="box-sizing: border-box">connecting to: mongodb://mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local:27017/admin?compressors=disabled&gssapiServiceName=mongodb<br style="box-sizing: border-box">Implicit session: session { "id" : UUID("dc18d908-e263-498f-adbe-dd3ca1d41659") }<br style="box-sizing: border-box">MongoDB server version: 4.2.21<br style="box-sizing: border-box">Server has startup warnings: <br style="box-sizing: border-box">2022-06-26T14:23:53.744+0000 ICONTROL ** WARNING: You are running this process as the root user, which is not recommended.<br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL <br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL <br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.<br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL ** We suggest setting it to 'never'<br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL <br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.<br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL ** We suggest setting it to 'never'<br style="box-sizing: border-box">2022-06-26T14:23:53.745+0000 ICONTROL <br style="box-sizing: border-box">---<br style="box-sizing: border-box">Enable MongoDB's free cloud-based monitoring service, which will then receive and display<br style="box-sizing: border-box">metrics about your deployment (disk utilization, CPU, operation statistics, etc).<br style="box-sizing: border-box"><br style="box-sizing: border-box">The monitoring data will be available on a MongoDB website with a unique URL accessible to you<br style="box-sizing: border-box">and anyone you share the URL with. MongoDB may use this information to make product<br style="box-sizing: border-box">improvements and to suggest MongoDB products and deployment options to you.<br style="box-sizing: border-box"><br style="box-sizing: border-box">To enable free monitoring, run the following command: db.enableFreeMonitoring()<br style="box-sizing: border-box">To permanently disable this reminder, run the following command: db.disableFreeMonitoring()<br style="box-sizing: border-box">---<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> db.getName();<br style="box-sizing: border-box">admin<br style="box-sizing: border-box">MainRepSet:PRIMARY> exit</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n89"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 8.9pt">补充: 验证登录方式</font></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n90"><font style="font-size: 10.8pt">root@mongodb-cluster-0:/# mongo<br style="box-sizing: border-box">MongoDB shell version v4.2.21<br style="box-sizing: border-box">connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br style="box-sizing: border-box">Implicit session: session { "id" : UUID("0cd67115-a016-4a69-82a6-99ba3fa74b54") }<br style="box-sizing: border-box">MongoDB server version: 4.2.21<br style="box-sizing: border-box">MainRepSet:PRIMARY> db.getSiblingDB('admin').auth("root", "liuchang123456");<br style="box-sizing: border-box">1<br style="box-sizing: border-box">MainRepSet:PRIMARY> db.getName();<br style="box-sizing: border-box">test<br style="box-sizing: border-box">MainRepSet:PRIMARY> exit</font></pre>
<h4 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n91"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">5 mongodb复制集测试</font></span></h4>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n92"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">5.1 将数据插入 mongodb-cluster-0 pod</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n93"><font style="font-size: 10.8pt">root@mongodb-cluster-0:/# mongo --host mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local \<br style="box-sizing: border-box">--port 27017 -uroot -p'liuchang123456' admin<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> use master_slave_test<br style="box-sizing: border-box">switched to db master_slave_test<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> function add(){var i = 0;for(;i<7;i++){db.persons.insert({"name":"master_slave_test"+i})}}<br style="box-sizing: border-box">MainRepSet:PRIMARY> add()<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> db.persons.find()<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e63"), "name" : "master_slave_test0" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e64"), "name" : "master_slave_test1" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e65"), "name" : "master_slave_test2" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e66"), "name" : "master_slave_test3" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e67"), "name" : "master_slave_test4" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e68"), "name" : "master_slave_test5" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e69"), "name" : "master_slave_test6" }<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> exit</font></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n94"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">5.2 在 mongodb-cluster-1 pod 中验证数据</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n95"><font style="font-size: 10.8pt">root@mongodb-cluster-0:/# mongo --host mongodb-cluster-1.mongodb-cluster.mongodb-cluster.svc.cluster.local \<br style="box-sizing: border-box">--port 27017 -uroot -p'liuchang123456' admin<br style="box-sizing: border-box">MainRepSet:SECONDARY> db.getMongo().setSecondaryOk()<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:SECONDARY> use master_slave_test<br style="box-sizing: border-box">switched to db master_slave_test<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:SECONDARY> db.persons.find()<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e63"), "name" : "master_slave_test0" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e64"), "name" : "master_slave_test1" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e67"), "name" : "master_slave_test4" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e66"), "name" : "master_slave_test3" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e69"), "name" : "master_slave_test6" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e65"), "name" : "master_slave_test2" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e68"), "name" : "master_slave_test5" }<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:SECONDARY> exit<br style="box-sizing: border-box">root@mongodb-cluster-0:/# exit</font></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n96"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">5.3 验证PVC</font></span></h5>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n97"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 8.9pt">1 删除整个mongodb副本集的pod</font></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n98"><font style="font-size: 10.8pt"># kubectl delete -f mongodb-statefulset.yaml<br style="box-sizing: border-box">service "mongodb-cluster" deleted<br style="box-sizing: border-box">statefulset.apps "mongodb-cluster" deleted<br style="box-sizing: border-box"><br style="box-sizing: border-box"># kubectl get all -n mongodb-cluster -o wide<br style="box-sizing: border-box">No resources found in mongodb-cluster namespace.</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n99"><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">注意:</font></code></span><font style="font-size: 8.9pt"><span class="md-softbreak" style="box-sizing: border-box" md-inline="softbreak">
</span><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box">这里只是删除了mongodb副本集的pod和service,对应的pvc、pv、存储并没有被删除。</code></span><span class="md-plain" style="box-sizing: border-box" md-inline="plain"> </span><span class="md-softbreak" style="box-sizing: border-box" md-inline="softbreak">
</span></font><span class="md-pair-s" style="box-sizing: border-box" spellcheck="false" md-inline="code"><code style="padding: 2px 4px; border-radius: 4px; text-align: left; box-sizing: border-box"><font style="font-size: 8.9pt">当重建pod时会重新占用对应的pvc, 因为pvc中使用了pod的名字,而statefulset又保持了pod的名称固定不变</font></code></span></p>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n100"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 8.9pt">2 重新创建mongodb副本集的pod</font></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n101"><font style="font-size: 10.8pt"># kubectl apply -f mongodb-statefulset.yaml <br style="box-sizing: border-box">service/mongodb-cluster created<br style="box-sizing: border-box">statefulset.apps/mongodb-cluster created<br style="box-sizing: border-box"><br style="box-sizing: border-box"># kubectl get all -n mongodb-cluster -o wide</font></pre>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n102"><span class="md-image md-img-loaded" style="width: 930px; vertical-align: top; display: inline-block; position: relative; -ms-word-break: break-all; min-height: 10px; min-width: 10px; box-sizing: border-box" md-inline="image" data-src="images/image-20220627001332674.png"><img width="1394" height="259" title="image-20220627001332674" style="border: 0 currentColor; border-image: none; vertical-align: middle; display: inline; cursor: default; max-width: 100%; box-sizing: border-box; background-image: none; image-orientation: from-image" alt="image-20220627001332674" src="https://img2022.cnblogs.com/blog/1616600/202206/1616600-20220627114925534-118082251.png" border="0" data-local-refresh="true" referrerpolicy="no-referrer"></span></p>
<p class="md-end-block md-p" style="margin: 11px 0; text-transform: none; line-height: inherit; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; box-sizing: border-box; orphans: 4; widows: 2; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="paragraph" cid="n103"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 8.9pt">3 验证mongodb副本集的数据</font></span></p>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n104"><font style="font-size: 10.8pt"># kubectl exec -it pod/mongodb-cluster-0 -n mongodb-cluster -- bash<br style="box-sizing: border-box">root@mongodb-cluster-0:/# mongo --host mongodb-cluster-0.mongodb-cluster.mongodb-cluster.svc.cluster.local \<br style="box-sizing: border-box">--port 27017 -uroot -p'liuchang123456' admin<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> use master_slave_test<br style="box-sizing: border-box">switched to db master_slave_test<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> db.persons.find()<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e63"), "name" : "master_slave_test0" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e64"), "name" : "master_slave_test1" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e65"), "name" : "master_slave_test2" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e66"), "name" : "master_slave_test3" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e67"), "name" : "master_slave_test4" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e68"), "name" : "master_slave_test5" }<br style="box-sizing: border-box">{ "_id" : ObjectId("62b87c308c229e35afd84e69"), "name" : "master_slave_test6" }<br style="box-sizing: border-box"><br style="box-sizing: border-box">MainRepSet:PRIMARY> exit<br style="box-sizing: border-box">bye<br style="box-sizing: border-box"><br style="box-sizing: border-box">root@mongodb-cluster-0:/# exit</font></pre>
<h5 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n105"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 12pt">5.4 验证集群化</font></span></h5>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n106"><font style="font-size: 10.8pt">删除 mongodb-cluster-0 pod 并继续检查 rs.status(),最终剩下的两个节点中的一个节点将成为 PRIMARY。</font></pre>
<h4 class="md-end-block md-heading" style="margin: 20px 0; text-transform: none; line-height: 1.4; text-indent: 0; letter-spacing: normal; word-spacing: 0; white-space: pre-wrap; position: relative; cursor: text; box-sizing: border-box; orphans: 4; widows: 2; break-after: avoid-page; break-inside: avoid; background-color: rgba(255, 255, 255, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" mdtype="heading" cid="n107"><span class="md-plain" style="box-sizing: border-box" md-inline="plain"><font style="font-size: 15pt">6 mongodb副本集数据备份</font></span></h4>
<pre class="md-fences mock-cm md-end-block" lang="" style="padding: 8px 0 6px; border-radius: 3px; width: inherit; text-align: left; text-transform: none; text-indent: 0; letter-spacing: normal; overflow: visible; margin-top: 15px; margin-bottom: 15px; word-spacing: 0; display: block; white-space: pre-wrap; position: relative !important; box-sizing: border-box; orphans: 2; widows: 2; break-inside: avoid; background-image: inherit; background-attachment: inherit; background-size: inherit; background-origin: inherit; background-clip: inherit; background-color: rgba(248, 248, 248, 1); font-variant-ligatures: normal; font-variant-caps: normal; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial" spellcheck="false" mdtype="fences" cid="n108"><font style="font-size: 10.8pt">只要连接到mongodb副本集中的任意一个pod都可以实现mongodb的数据备份,那么怎样才能连接上呢,这里提供两种思路。<br style="box-sizing: border-box">(1) 在k8s集群中找一个节点,修改"/etc/resolv.conf"文件,将k8s集群的dns域名解析配置放到首位即可。<br style="box-sizing: border-box">(2) 添加一个类型为nodePort的service,这样k8s的每个节点上都会有"27017"监听端口。</font></pre><br class="Apple-interchange-newline"><br><br>
来源:https://www.cnblogs.com/LiuChang-blog/p/16415657.html
頁:
[1]