{"id":6903,"date":"2026-05-08T04:14:09","date_gmt":"2026-05-07T20:14:09","guid":{"rendered":"https:\/\/www.babel.cc\/blog\/?p=6903"},"modified":"2026-05-08T04:14:09","modified_gmt":"2026-05-07T20:14:09","slug":"%e4%bc%81%e4%b8%9a%e4%ba%91%e7%9b%98%e8%bf%90%e7%bb%b4%e8%87%aa%e5%8a%a8%e5%8c%96%ef%bc%9aansible%e8%84%9a%e6%9c%ac%e4%b8%8eci-cd%e6%b5%81%e6%b0%b4%e7%ba%bf%e5%ae%9e%e6%88%98","status":"publish","type":"post","link":"https:\/\/www.babel.cc\/blog\/?p=6903","title":{"rendered":"\u4f01\u4e1a\u4e91\u76d8\u8fd0\u7ef4\u81ea\u52a8\u5316\uff1aAnsible\u811a\u672c\u4e0eCI-CD\u6d41\u6c34\u7ebf\u5b9e\u6218"},"content":{"rendered":"<p># \u4f01\u4e1a\u4e91\u76d8\u8fd0\u7ef4\u81ea\u52a8\u5316\uff1aAnsible\u811a\u672c\u4e0eCI\/CD\u6d41\u6c34\u7ebf\u5b9e\u6218<\/p>\n<p>> **\u4f5c\u8005\uff1a\u5df4\u522b\u9e1f\u6280\u672f\u56e2\u961f**<br \/>\n> **\u80cc\u666f\uff1a** \u5df4\u522b\u9e1f\u4f01\u4e1a\u4e91\u76d8\u670d\u52a1\u7740\u6570\u767e\u5bb6\u4f01\u4e1a\u5ba2\u6237\uff0c\u96c6\u7fa4\u89c4\u6a21\u6570\u5341\u53f0\u670d\u52a1\u5668\uff0c\u6db5\u76d6K8s\u8282\u70b9\u3001\u5b58\u50a8\u8282\u70b9\u3001\u8d1f\u8f7d\u5747\u8861\u8282\u70b9\u7b49\u591a\u79cd\u89d2\u8272\u3002\u5728\u8fd9\u6837\u7684\u89c4\u6a21\u4e0b\uff0c\u7eaf\u624b\u5de5\u8fd0\u7ef4\u5df2\u7ecf\u65e0\u6cd5\u4fdd\u8bc1\u6548\u7387\u548c\u4e00\u81f4\u6027\u3002\u672c\u6587\u8bb0\u5f55\u5df4\u522b\u9e1f\u5982\u4f55\u7528Ansible\u5b9e\u73b0\u914d\u7f6e\u6807\u51c6\u5316\uff0c\u7528CI\/CD\u6d41\u6c34\u7ebf\u5b9e\u73b0\u53d1\u5e03\u81ea\u52a8\u5316\uff0c\u4ee5\u53ca\u90a3\u4e9b\u8ba9\u6211\u4eec\u8e29\u8fc7\u65e0\u6570\u5751\u624d\u603b\u7ed3\u51fa\u6765\u7684\u7ecf\u9a8c\u3002<br \/>\n> **\u524d\u7f6e\u8bf4\u660e\uff1a** \u672c\u6587\u6240\u6709\u811a\u672c\u5747\u4e3a\u751f\u4ea7\u73af\u5883\u5b9e\u9645\u8fd0\u884c\u4ee3\u7801\uff0c\u7ecf\u8fc7\u81f3\u5c111\u5e74\u9a8c\u8bc1\u3002\u5185\u5bb9\u504f\u5b9e\u6218\uff0c\u4e0d\u8bb2\u6982\u5ff5\uff0c\u76f4\u63a5\u4e0a\u4ee3\u7801\u548c\u8e29\u5751\u8bb0\u5f55\u3002<\/p>\n<p>&#8212;<\/p>\n<p>## \u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981\u81ea\u52a8\u5316\u8fd0\u7ef4<\/p>\n<p>### 1.1 \u624b\u5de5\u8fd0\u7ef4\u7684\u5929\u82b1\u677f<\/p>\n<p>\u5df4\u522b\u9e1f\u7684\u8fd0\u7ef4\u7ecf\u5386\u4e86\u51e0\u4e2a\u9636\u6bb5\uff0c\u6bcf\u4e2a\u9636\u6bb5\u90fd\u9047\u5230\u4e86\u74f6\u9888\uff1a<\/p>\n<p>**\u9636\u6bb5\u4e00\uff1aSSH\u8fde\u4e0a\u53bb\u624b\u6572\u547d\u4ee4**<\/p>\n<p>&#8220;`bash<br \/>\n# \u767b\u5f55\u5230\u6bcf\u4e00\u53f0\u673a\u5668\uff0c\u624b\u52a8\u6267\u884c<br \/>\nssh root@192.168.1.10<br \/>\ncd \/opt\/babelbird<br \/>\n.\/stop.sh<br \/>\ntar -xzf babelbird-2.3.0.tar.gz<br \/>\n.\/start.sh<br \/>\n&#8220;`<\/p>\n<p>\u95ee\u9898\uff1a<br \/>\n&#8211; 10\u53f0\u673a\u5668\u5c31\u8981\u91cd\u590d10\u6b21<br \/>\n&#8211; \u67d0\u53f0\u673a\u5668\u6572\u9519\u4e86\u547d\u4ee4\uff0c\u67e5\u90fd\u67e5\u4e0d\u51fa\u6765<br \/>\n&#8211; \u56de\u6eda\uff1f\u505a\u68a6\u5427<br \/>\n&#8211; \u51cc\u66683\u70b9\u624b\u6296\u6572\u9519\u547d\u4ee4\uff0c\u5dee\u70b9\u628a\u751f\u4ea7\u73af\u5883\u641e\u6302<\/p>\n<p>**\u9636\u6bb5\u4e8c\uff1a\u811a\u672c\u5316**<\/p>\n<p>&#8220;`bash<br \/>\n#!\/bin\/bash<br \/>\nfor host in $(cat hosts.txt); do<br \/>\n    ssh root@$host &#8220;cd \/opt\/babelbird &#038;&#038; .\/deploy.sh babelbird-2.3.0.tar.gz&#8221;<br \/>\ndone<br \/>\n&#8220;`<\/p>\n<p>\u8fdb\u6b65\u4e86\uff0c\u4f46\u95ee\u9898\u66f4\u591a\uff1a<br \/>\n&#8211; SSH\u8fde\u63a5\u4e0d\u7a33\u5b9a\uff0c\u811a\u672c\u4e2d\u95f4\u65ad\u4e86\u4e0d\u77e5\u9053\u4ece\u54ea\u7ee7\u7eed<br \/>\n&#8211; \u6ca1\u6709\u65e5\u5fd7\uff0c\u5931\u8d25\u4e86\u4f60\u90fd\u4e0d\u77e5\u9053\u54ea\u53f0\u673a\u5668\u51fa\u4e86\u95ee\u9898<br \/>\n&#8211; \u6ca1\u6709\u72b6\u6001\u68c0\u67e5\uff0c\u4e0d\u77e5\u9053\u670d\u52a1\u5230\u5e95\u542f\u52a8\u6ca1\u6709<br \/>\n&#8211; \u591a\u4eba\u534f\u4f5c\u65f6\u811a\u672c\u7248\u672c\u7ba1\u7406\u6df7\u4e71<\/p>\n<p>**\u9636\u6bb5\u4e09\uff1aAnsible + CI\/CD\uff08\u5f53\u524d\uff09**<\/p>\n<p>\u5f53\u524d\u65b9\u6848\u89e3\u51b3\u4e86\u6240\u6709\u624b\u5de5\u8fd0\u7ef4\u7684\u95ee\u9898\uff1a<br \/>\n&#8211; \u5e42\u7b49\u6267\u884c\uff1a\u6267\u884c100\u6b21\u548c\u6267\u884c1\u6b21\u7ed3\u679c\u4e00\u6837<br \/>\n&#8211; \u65e5\u5fd7\u5b8c\u6574\uff1a\u6bcf\u4e00\u6b65\u64cd\u4f5c\u90fd\u6709\u8bb0\u5f55<br \/>\n&#8211; \u72b6\u6001\u9a71\u52a8\uff1a\u914d\u7f6e\u53d8\u4e86\u624d\u6539\uff0c\u4e0d\u53d8\u4e0d\u52a8<br \/>\n&#8211; \u6d41\u6c34\u7ebf\u5316\uff1a\u4ee3\u7801\u63d0\u4ea4\u81ea\u52a8\u89e6\u53d1\uff0c\u4e0d\u7528\u4eba\u5b88\u7740<\/p>\n<p>&#8212;<\/p>\n<p>## \u4e8c\u3001Ansible\u57fa\u7840\u67b6\u6784\u8bbe\u8ba1<\/p>\n<p>### 2.1 \u4e3a\u4ec0\u4e48\u9009Ansible\u800c\u4e0d\u662f\u522b\u7684<\/p>\n<p>| \u5de5\u5177 | Agent\u9700\u6c42 | \u5b66\u4e60\u6210\u672c | \u8868\u8fbe\u80fd\u529b | \u9002\u5408\u573a\u666f |<br \/>\n|&#8212;&#8212;|&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;-|<br \/>\n| **Ansible** | \u65e0\uff08SSH\uff09 | \u4f4e | \u4e2d\uff08YAML Playbook\uff09 | \u914d\u7f6e\u7ba1\u7406\u3001\u6279\u91cf\u6267\u884c |<br \/>\n| **Chef** | \u6709 | \u9ad8 | \u9ad8\uff08Ruby DSL\uff09 | \u590d\u6742\u914d\u7f6e\u7ba1\u7406 |<br \/>\n| **Puppet** | \u6709 | \u9ad8 | \u9ad8\uff08Hiera\/PP\uff09 | \u5927\u89c4\u6a21\u57fa\u7840\u8bbe\u65bd |<br \/>\n| **SaltStack** | \u6709 | \u4e2d | \u9ad8\uff08YAML+Jinja\uff09 | \u9ad8\u6027\u80fd\u9700\u6c42 |<br \/>\n| **Terraform** | \u65e0 | \u4e2d | \u9ad8\uff08HCL\uff09 | \u57fa\u7840\u8bbe\u65bd\u7f16\u6392 |<\/p>\n<p>\u5df4\u522b\u9e1f\u9009Ansible\u7684\u539f\u56e0\uff1a<br \/>\n1. **\u65e0Agent**\uff1a\u4e0d\u9700\u8981\u5728\u88ab\u7ba1\u7406\u673a\u5668\u4e0a\u88c5\u8f6f\u4ef6\uff0cSSH\u53ef\u8fbe\u5373\u53ef<br \/>\n2. **\u5e42\u7b49**\uff1aAnsible\u7684\u6a21\u5757\u90fd\u662f\u5e42\u7b49\u7684\uff0c\u6267\u884c\u591a\u5c11\u6b21\u7ed3\u679c\u90fd\u4e00\u6837<br \/>\n3. **\u793e\u533a\u6210\u719f**\uff1a\u5b98\u65b9\u548c\u793e\u533a\u7684Role\u975e\u5e38\u4e30\u5bcc\uff0c\u5927\u90e8\u5206\u5e38\u89c1\u64cd\u4f5c\u4e0d\u7528\u81ea\u5df1\u5199<br \/>\n4. **\u5b66\u4e60\u6210\u672c\u4f4e**\uff1aYAML\u683c\u5f0f\uff0c\u8fd0\u7ef4\u540c\u5b66\u5bb9\u6613\u4e0a\u624b<\/p>\n<p>### 2.2 \u76ee\u5f55\u7ed3\u6784\u8bbe\u8ba1<\/p>\n<p>&#8220;`<br \/>\nbabelbird-ansible\/<br \/>\n\u251c\u2500\u2500 ansible.cfg                 # Ansible\u5168\u5c40\u914d\u7f6e<br \/>\n\u251c\u2500\u2500 hosts                       # \u8d44\u4ea7\u6e05\u5355\uff08\u652f\u6301\u9759\u6001\u548c\u52a8\u6001Inventory\uff09<br \/>\n\u251c\u2500\u2500 playbooks\/                  # Playbook\u96c6\u5408<br \/>\n\u2502   \u251c\u2500\u2500 common\/                # \u901a\u7528Playbook\uff08\u521d\u59cb\u5316\u3001\u914d\u7f6e\u540c\u6b65\uff09<br \/>\n\u2502   \u251c\u2500\u2500 deploy\/                # \u5e94\u7528\u90e8\u7f72Playbook<br \/>\n\u2502   \u251c\u2500\u2500 monitoring\/           # \u76d1\u63a7\u7ec4\u4ef6\u90e8\u7f72<br \/>\n\u2502   \u2514\u2500\u2500 maintenance\/           # \u7ef4\u62a4\u7c7bPlaybook\uff08\u5907\u4efd\u3001\u5347\u7ea7\u3001\u56de\u6eda\uff09<br \/>\n\u251c\u2500\u2500 roles\/                     # Roles\u96c6\u5408\uff08\u53ef\u590d\u7528\uff09<br \/>\n\u2502   \u251c\u2500\u2500 common\/               # \u901a\u7528\u89d2\u8272\uff08\u4e3b\u673a\u540d\/\u65f6\u533a\/NTP\uff09<br \/>\n\u2502   \u251c\u2500\u2500 docker\/               # Docker\u5b89\u88c5\u914d\u7f6e<br \/>\n\u2502   \u251c\u2500\u2500 k8s-node\/            # K8s\u8282\u70b9\u914d\u7f6e<br \/>\n\u2502   \u251c\u2500\u2500 babelbird-app\/       # \u5df4\u522b\u9e1f\u5e94\u7528\u672c\u8eab<br \/>\n\u2502   \u251c\u2500\u2500 prometheus-node\/     # Prometheus\u76f8\u5173Exporter<br \/>\n\u2502   \u2514\u2500\u2500 alerting\/            # \u544a\u8b66\u7ec4\u4ef6<br \/>\n\u251c\u2500\u2500 library\/                  # \u81ea\u5b9a\u4e49Ansible\u6a21\u5757<br \/>\n\u251c\u2500\u2500 callback_plugins\/        # \u81ea\u5b9a\u4e49\u56de\u8c03\u63d2\u4ef6\uff08\u65e5\u5fd7\u589e\u5f3a\uff09<br \/>\n\u251c\u2500\u2500 inventory\/               # \u52a8\u6001Inventory\u811a\u672c<br \/>\n\u2514\u2500\u2500 group_vars\/              # \u5168\u5c40\u53d8\u91cf<br \/>\n    \u251c\u2500\u2500 all.yml<br \/>\n    \u251c\u2500\u2500 production.yml<br \/>\n    \u2514\u2500\u2500 staging.yml<br \/>\n&#8220;`<\/p>\n<p>### 2.3 ansible.cfg\u751f\u4ea7\u7ea7\u914d\u7f6e<\/p>\n<p>&#8220;`ini<br \/>\n[defaults]<br \/>\n# inventory\u6587\u4ef6\u8def\u5f84<br \/>\ninventory = .\/hosts<\/p>\n<p># \u5e76\u53d1\u6570\uff0c\u751f\u4ea7\u73af\u5883\u53ef\u4ee5\u5f00\u9ad8\u4e00\u70b9<br \/>\nforks = 20<\/p>\n<p># \u8fdc\u7a0b\u7528\u6237<br \/>\nremote_user = deploy<\/p>\n<p># \u79c1\u6709\u5bc6\u94a5\uff08\u5efa\u8bae\u7528SSH Agent\u800c\u4e0d\u662f\u5199\u6b7b\u5728\u8fd9\u91cc\uff09<br \/>\n# private_key_file = ~\/.ssh\/id_rsa<\/p>\n<p># SSH\u8fde\u63a5\u53c2\u6570\u4f18\u5316<br \/>\ntimeout = 30<br \/>\ngathering = smart<br \/>\nfact_caching = jsonfile<br \/>\nfact_caching_connection = \/tmp\/ansible_facts<br \/>\nfact_caching_timeout = 86400<\/p>\n<p># \u65e5\u5fd7\u914d\u7f6e<br \/>\nlog_path = \/var\/log\/ansible\/ansible.log<br \/>\nno_log = False<\/p>\n<p># \u56de\u8c03\u63d2\u4ef6\uff08\u589e\u5f3a\u8f93\u51fa\uff09<br \/>\ncallback_plugins = .\/callback_plugins<br \/>\ncallbacks_enabled = timer, profile_tasks, yaml_output<\/p>\n<p># \u9996\u6b21\u8fde\u63a5\u65f6\u4e0d\u68c0\u67e5hostkey\uff08\u9002\u7528\u4e8e\u65b0\u673a\u5668\u521d\u59cb\u5316\uff09<br \/>\nhost_key_checking = False<\/p>\n<p># \u5f00\u542fpipelining\uff0cSSH\u8fde\u63a5\u6570\u51cf\u5c11\uff0c\u901f\u5ea6\u63d0\u5347\u7ea630%<br \/>\npipelining = True<\/p>\n<p># \u5f00\u542f\u5f02\u6b65\u6267\u884c\uff08\u9002\u7528\u4e8e\u8017\u65f6\u4efb\u52a1\uff09<br \/>\nasync_timeout = 3600<br \/>\npoll_interval = 15<\/p>\n<p>[privilege_escalation]<br \/>\n# sudo\u914d\u7f6e<br \/>\nbecome = True<br \/>\nbecome_method = sudo<br \/>\nbecome_user = root<br \/>\nbecome_ask_pass = False<\/p>\n<p>[ssh_connection]<br \/>\n# SSH\u8fde\u63a5\u4f18\u5316\u53c2\u6570<br \/>\npipelining = True<br \/>\n# \u5931\u8d25\u91cd\u8bd5\u6b21\u6570<br \/>\nretries = 3<br \/>\n# ControlPersist\u51cf\u5c11SSH\u63e1\u624b\u5f00\u9500<br \/>\ncontrol_path = \/tmp\/ansible-ssh-%%h-%%p-%%r<br \/>\nssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no<\/p>\n<p>[inventory]<br \/>\n# \u52a8\u6001Inventory\u652f\u6301<br \/>\nenable_plugins = yaml, ini, host_list, script<br \/>\n&#8220;`<\/p>\n<p>### 2.4 hosts\u8d44\u4ea7\u6e05\u5355\u914d\u7f6e<\/p>\n<p>&#8220;`yaml<br \/>\n# hosts\uff08YAML\u683c\u5f0f\uff0c\u652f\u6301\u5206\u5c42\uff09<br \/>\nall:<br \/>\n  vars:<br \/>\n    ansible_user: deploy<br \/>\n    ansible_port: 22<br \/>\n    ansible_python_interpreter: \/usr\/bin\/python3<br \/>\n    # \u7edf\u4e00\u65f6\u533a<br \/>\n    timezone: Asia\/Shanghai<br \/>\n    # NTP\u670d\u52a1\u5668<br \/>\n    ntp_server: ntp.babelbird.com<br \/>\n    # Docker\u955c\u50cf\u4ed3\u5e93<br \/>\n    docker_registry: registry.babelbird.com<br \/>\n    docker_registry_username: deploy<br \/>\n    # \u5e94\u7528\u7248\u672c\uff08\u901a\u8fc7CI\/CD\u6ce8\u5165\uff09<br \/>\n    babelbird_version: &#8220;&#8221;<br \/>\n    babelbird_deploy_user: babelbird<br \/>\n    babelbird_deploy_group: babelbird<\/p>\n<p>  children:<br \/>\n    # \u8df3\u677f\u673a\uff08\u4e0d\u53c2\u4e0e\u90e8\u7f72\uff0c\u4ec5\u505aSSH\u4ee3\u7406\uff09<br \/>\n    bastion:<br \/>\n      hosts:<br \/>\n        bastion-01:<br \/>\n          ansible_host: 10.0.0.1<br \/>\n          ansible_user: deploy<br \/>\n        bastion-02:<br \/>\n          ansible_host: 10.0.0.2<br \/>\n          ansible_user: deploy<\/p>\n<p>    # K8s Master\u8282\u70b9<br \/>\n    k8s_masters:<br \/>\n      hosts:<br \/>\n        k8s-master-01:<br \/>\n          ansible_host: 10.0.1.11<br \/>\n          etcd_member_name: etcd-01<br \/>\n          node_labels:<br \/>\n            &#8211; node-role.kubernetes.io\/control-plane<br \/>\n            &#8211; node-role.kubernetes.io\/master<br \/>\n        k8s-master-02:<br \/>\n          ansible_host: 10.0.1.12<br \/>\n          etcd_member_name: etcd-02<br \/>\n          node_labels:<br \/>\n            &#8211; node-role.kubernetes.io\/control-plane<br \/>\n            &#8211; node-role.kubernetes.io\/master<br \/>\n        k8s-master-03:<br \/>\n          ansible_host: 10.0.1.13<br \/>\n          etcd_member_name: etcd-03<br \/>\n          node_labels:<br \/>\n            &#8211; node-role.kubernetes.io\/control-plane<br \/>\n            &#8211; node-role.kubernetes.io\/master<\/p>\n<p>    # K8s Worker\u8282\u70b9<br \/>\n    k8s_workers:<br \/>\n      vars:<br \/>\n        # Worker\u8282\u70b9\u9ed8\u8ba4\u6807\u7b7e<br \/>\n        default_node_labels:<br \/>\n          babelbird\/storage-node: &#8220;true&#8221;<br \/>\n      hosts:<br \/>\n        k8s-worker-01:<br \/>\n          ansible_host: 10.0.2.11<br \/>\n          node_labels:<br \/>\n            &#8211; babelbird\/app-node: &#8220;true&#8221;<br \/>\n            &#8211; babelbird\/storage-tier: hot<br \/>\n        k8s-worker-02:<br \/>\n          ansible_host: 10.0.2.12<br \/>\n          node_labels:<br \/>\n            &#8211; babelbird\/app-node: &#8220;true&#8221;<br \/>\n            &#8211; babelbird\/storage-tier: hot<br \/>\n        k8s-worker-03:<br \/>\n          ansible_host: 10.0.2.13<br \/>\n          node_labels:<br \/>\n            &#8211; babelbird\/app-node: &#8220;true&#8221;<br \/>\n            &#8211; babelbird\/storage-tier: warm<br \/>\n        k8s-worker-04:<br \/>\n          ansible_host: 10.0.2.14<br \/>\n          node_labels:<br \/>\n            &#8211; babelbird\/app-node: &#8220;true&#8221;<br \/>\n            &#8211; babelbird\/storage-tier: cold<\/p>\n<p>    # \u5b58\u50a8\u8282\u70b9\uff08\u72ec\u7acbCeph\/MinIO\u96c6\u7fa4\uff09<br \/>\n    storage_nodes:<br \/>\n      hosts:<br \/>\n        storage-node-01:<br \/>\n          ansible_host: 10.0.3.11<br \/>\n          storage_data_disk: \/dev\/sdb<br \/>\n          storage_journal_disk: \/dev\/sdc<br \/>\n        storage-node-02:<br \/>\n          ansible_host: 10.0.3.12<br \/>\n          storage_data_disk: \/dev\/sdb<br \/>\n          storage_journal_disk: \/dev\/sdc<br \/>\n        storage-node-03:<br \/>\n          ansible_host: 10.0.3.13<br \/>\n          storage_data_disk: \/dev\/sdb<br \/>\n          storage_journal_disk: \/dev\/sdc<\/p>\n<p>    # \u8d1f\u8f7d\u5747\u8861\u8282\u70b9\uff08Nginx\/HAProxy\uff09<br \/>\n    lb_nodes:<br \/>\n      hosts:<br \/>\n        lb-node-01:<br \/>\n          ansible_host: 10.0.4.11<br \/>\n          haproxy_stats_enabled: true<br \/>\n          haproxy_stats_port: 9000<br \/>\n        lb-node-02:<br \/>\n          ansible_host: 10.0.4.12<br \/>\n          haproxy_stats_enabled: true<br \/>\n          haproxy_stats_port: 9000<\/p>\n<p>    # \u76d1\u63a7\u8282\u70b9\uff08Prometheus\/Grafana\/Alertmanager\uff09<br \/>\n    monitoring_nodes:<br \/>\n      hosts:<br \/>\n        monitor-01:<br \/>\n          ansible_host: 10.0.5.11<br \/>\n          prometheus_storage_size: 200Gi<br \/>\n        monitor-02:<br \/>\n          ansible_host: 10.0.5.12<br \/>\n          prometheus_storage_size: 200Gi<\/p>\n<p>    # \u6570\u636e\u5e93\u8282\u70b9\uff08PostgreSQL\u4e3b\u4ece\uff09<br \/>\n    database_nodes:<br \/>\n      vars:<br \/>\n        pg_port: 5432<br \/>\n        pg_version: &#8220;15&#8221;<br \/>\n        pg_max_connections: 500<br \/>\n      hosts:<br \/>\n        db-master:<br \/>\n          ansible_host: 10.0.6.11<br \/>\n          pg_role: master<br \/>\n          pg_replication_slots: 5<br \/>\n        db-slave-01:<br \/>\n          ansible_host: 10.0.6.12<br \/>\n          pg_role: replica<br \/>\n          pg_replication_slot_name: db_slave_01<br \/>\n        db-slave-02:<br \/>\n          ansible_host: 10.0.6.13<br \/>\n          pg_role: replica<br \/>\n          pg_replication_slot_name: db_slave_02<\/p>\n<p>  # \u8de8\u7ec4\u5b9a\u4e49\uff08\u7528\u4e8e\u8d1f\u8f7d\u5747\u8861\u7b49\u573a\u666f\uff09<br \/>\n  children_groups_define:<br \/>\n    # \u6240\u6709K8s\u8282\u70b9\uff08Master + Worker\uff09<br \/>\n    k8s_all:<br \/>\n      &#8211; k8s_masters<br \/>\n      &#8211; k8s_workers<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<p>## \u4e09\u3001\u6838\u5fc3Playbook\u4e0eRole\u5b9e\u6218<\/p>\n<p>### 3.1 \u901a\u7528\u521d\u59cb\u5316Playbook\uff08\u6240\u6709\u65b0\u673a\u5668\u5fc5\u8dd1\uff09<\/p>\n<p>&#8220;`yaml<br \/>\n# playbooks\/common\/init-server.yml<br \/>\n&#8212;<br \/>\n# \u7528\u9014\uff1a\u65b0\u673a\u5668\u521d\u59cb\u5316\u6216\u91cd\u7f6e\u540e\u6267\u884c\uff0c\u786e\u4fdd\u6240\u6709\u670d\u52a1\u5668\u57fa\u7840\u914d\u7f6e\u4e00\u81f4<br \/>\n# \u4f7f\u7528\u524d\u63d0\uff1a\u5df2\u5728hosts\u4e2d\u5b9a\u4e49\u597d\u8d44\u4ea7\u6e05\u5355<br \/>\n# \u6267\u884c\u65b9\u5f0f\uff1aansible-playbook playbooks\/common\/init-server.yml -l new-server-01<\/p>\n<p>&#8211; name: \u670d\u52a1\u5668\u521d\u59cb\u5316\uff08\u6240\u6709\u65b0\u673a\u5668\u5fc5\u8dd1\uff09<br \/>\n  hosts: all<br \/>\n  become: true<br \/>\n  gather_facts: true  # \u5fc5\u987b\u6253\u5f00\uff0c\u521d\u59cb\u5316\u65f6\u9700\u8981\u83b7\u53d6\u7cfb\u7edf\u4fe1\u606f<\/p>\n<p>  vars:<br \/>\n    ntp_server: ntp.babelbird.com<br \/>\n    timezone: Asia\/Shanghai<br \/>\n    sysctl_params:<br \/>\n      # \u5185\u6838\u53c2\u6570\u4f18\u5316\uff08\u7f51\u7edc\uff09<br \/>\n      net.core.somaxconn: 65535<br \/>\n      net.ipv4.tcp_tw_reuse: 1<br \/>\n      net.ipv4.tcp_fin_timeout: 30<br \/>\n      net.ipv4.ip_local_port_range: &#8220;1024 65535&#8221;<br \/>\n      # \u6587\u4ef6\u63cf\u8ff0\u7b26<br \/>\n      fs.file-max: 2097152<br \/>\n      # \u7981\u7528IPv6\uff08\u5982\u679c\u4e0d\u9700\u8981\uff09<br \/>\n      net.ipv6.conf.all.disable_ipv6: 1<br \/>\n      net.ipv6.conf.default.disable_ipv6: 1<br \/>\n      # \u900f\u660e\u5de8\u9875\uff08\u5bf9\u6570\u636e\u5e93\u548cJava\u670d\u52a1\u91cd\u8981\uff09<br \/>\n      vm.nr_hugepages: 128<br \/>\n      # \u4ea4\u6362\u5206\u533a\u7b56\u7565\uff08\u5b81\u53efOOM\u4e0d\u8981\u9891\u7e41swap\uff09<br \/>\n      vm.swappiness: 10<br \/>\n      vm.dirty_ratio: 15<br \/>\n      vm.dirty_background_ratio: 5<\/p>\n<p>  roles:<br \/>\n    &#8211; { role: common, tags: [common, init] }<br \/>\n    &#8211; { role: docker, tags: [docker] }<br \/>\n    &#8211; { role: monitoring-node-exporter, tags: [monitoring] }<\/p>\n<p>  tasks:<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u57fa\u7840\u73af\u5883\u68c0\u67e5<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u68c0\u67e5\u662f\u5426\u4e3a\u652f\u6301\u7684Linux\u53d1\u884c\u7248<br \/>\n      assert:<br \/>\n        that:<br \/>\n          &#8211; ansible_facts[&#8216;distribution&#8217;] in [&#8216;CentOS&#8217;, &#8216;Rocky&#8217;, &#8216;AlmaLinux&#8217;, &#8216;Ubuntu&#8217;, &#8216;Debian&#8217;]<br \/>\n        fail_msg: &#8220;\u4ec5\u652f\u6301CentOS\/Rocky\/AlmaLinux\/Ubuntu\/Debian\uff0c\u5f53\u524d\u7cfb\u7edf: {{ ansible_facts[&#8216;distribution&#8217;] }}&#8221;<br \/>\n        quiet: true<\/p>\n<p>    &#8211; name: \u68c0\u67e5\u662f\u5426\u4e3aroot\u7528\u6237\u6267\u884c<br \/>\n      assert:<br \/>\n        that:<br \/>\n          &#8211; ansible_user_id == &#8216;root&#8217; or ansible_become == true<br \/>\n        fail_msg: &#8220;\u5fc5\u987b\u4f7f\u7528root\u7528\u6237\u6216\u5177\u6709sudo\u6743\u9650\u6267\u884c\u6b64Playbook&#8221;<br \/>\n        quiet: true<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u7cfb\u7edf\u57fa\u7840\u914d\u7f6e<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u8bbe\u7f6e\u4e3b\u673a\u540d\uff08\u5982\u679c\u4e0einventory\u4e0d\u4e00\u81f4\uff09<br \/>\n      hostname:<br \/>\n        name: &#8220;{{ inventory_hostname }}&#8221;<br \/>\n      when: ansible_facts[&#8216;hostname&#8217;] != inventory_hostname<\/p>\n<p>    &#8211; name: \u914d\u7f6e\/etc\/hosts\uff08\u786e\u4fdd\u4e3b\u673a\u540d\u89e3\u6790\u6b63\u5e38\uff09<br \/>\n      blockinfile:<br \/>\n        path: \/etc\/hosts<br \/>\n        marker: &#8220;# {mark} ANSIBLE MANAGED BLOCK &#8211; babelbird&#8221;<br \/>\n        block: |<br \/>\n          127.0.0.1 localhost<br \/>\n          ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6<br \/>\n          {% for host in groups[&#8216;all&#8217;] %}<br \/>\n          {{ hostvars[host][&#8216;ansible_host&#8217;] }} {{ hostvars[host][&#8216;inventory_hostname&#8217;] }}<br \/>\n          {% endfor %}<\/p>\n<p>    &#8211; name: \u914d\u7f6e\u65f6\u533a<br \/>\n      timezone:<br \/>\n        name: &#8220;{{ timezone }}&#8221;<br \/>\n      when: ansible_facts[&#8216;date_time.tz&#8217;] != timezone<\/p>\n<p>    &#8211; name: \u5b89\u88c5\u5e76\u542f\u52a8NTP\u670d\u52a1\uff08\u4f7f\u7528chrony\uff0c\u66f4\u73b0\u4ee3\uff09<br \/>\n      block:<br \/>\n        &#8211; name: \u5b89\u88c5chrony<br \/>\n          package:<br \/>\n            name: chrony<br \/>\n            state: present<\/p>\n<p>        &#8211; name: \u914d\u7f6echrony<br \/>\n          template:<br \/>\n            src: templates\/chrony.conf.j2<br \/>\n            dest: \/etc\/chrony.conf<br \/>\n            mode: &#8216;0644&#8217;<br \/>\n          notify: restart chronyd<\/p>\n<p>        &#8211; name: \u542f\u52a8\u5e76\u542f\u7528chronyd<br \/>\n          service:<br \/>\n            name: chronyd<br \/>\n            state: started<br \/>\n            enabled: true<br \/>\n      when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;CentOS&#8217;, &#8216;Rocky&#8217;, &#8216;AlmaLinux&#8217;]<\/p>\n<p>    &#8211; name: \u5b89\u88c5\u5e76\u542f\u52a8NTP\u670d\u52a1\uff08Debian\/Ubuntu\uff09<br \/>\n      block:<br \/>\n        &#8211; name: \u5b89\u88c5chrony\uff08Debian\/Ubuntu\uff09<br \/>\n          apt:<br \/>\n            name: chrony<br \/>\n            state: present<br \/>\n            update_cache: yes<\/p>\n<p>        &#8211; name: \u914d\u7f6echrony<br \/>\n          template:<br \/>\n            src: templates\/chrony.conf.j2<br \/>\n            dest: \/etc\/chrony\/chrony.conf<br \/>\n            mode: &#8216;0644&#8217;<br \/>\n          notify: restart chronyd<\/p>\n<p>        &#8211; name: \u542f\u52a8\u5e76\u542f\u7528chronyd<br \/>\n          service:<br \/>\n            name: chrony<br \/>\n            state: started<br \/>\n            enabled: true<br \/>\n      when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u5185\u6838\u53c2\u6570\u4f18\u5316<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u914d\u7f6e\u5185\u6838\u53c2\u6570\uff08sysctl\uff09<br \/>\n      sysctl:<br \/>\n        name: &#8220;{{ item.key }}&#8221;<br \/>\n        value: &#8220;{{ item.value }}&#8221;<br \/>\n        state: present<br \/>\n        reload: true<br \/>\n        sysctl_file: \/etc\/sysctl.d\/99-babelbird.conf<br \/>\n      loop: &#8220;{{ sysctl_params | dict2items }}&#8221;<br \/>\n      when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;CentOS&#8217;, &#8216;Rocky&#8217;, &#8216;AlmaLinux&#8217;]<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u7cfb\u7edf\u8d44\u6e90\u9650\u5236<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u914d\u7f6e\u7cfb\u7edf\u8d44\u6e90\u9650\u5236\uff08limits.conf\uff09<br \/>\n      blockinfile:<br \/>\n        path: \/etc\/security\/limits.conf<br \/>\n        marker: &#8220;# {mark} ANSIBLE MANAGED &#8211; babelbird&#8221;<br \/>\n        block: |<br \/>\n          # \u6587\u4ef6\u63cf\u8ff0\u7b26\u9650\u5236<br \/>\n          * soft nofile 1048576<br \/>\n          * hard nofile 1048576<br \/>\n          # \u8fdb\u7a0b\u6570\u9650\u5236<br \/>\n          * soft nproc 1048576<br \/>\n          * hard nproc 1048576<br \/>\n          # \u5185\u5b58\u9501\u9650\u5236\uff08\u5bf9\u6570\u636e\u5e93\u548c\u5185\u5b58\u7f13\u5b58\u91cd\u8981\uff09<br \/>\n          * soft memlock unlimited<br \/>\n          * hard memlock unlimited<br \/>\n          # Core Dump\u5927\u5c0f<br \/>\n          * soft core unlimited<br \/>\n          * hard core unlimited<br \/>\n          # Root\u7528\u6237\u5355\u72ec\u914d\u7f6e<br \/>\n          root soft nofile 1048576<br \/>\n          root hard nofile 1048576<\/p>\n<p>    &#8211; name: \u914d\u7f6esystemd\u8d44\u6e90\u9650\u5236\uff08\u8986\u76d6limits.conf\uff09<br \/>\n      template:<br \/>\n        src: templates\/limits.conf.j2<br \/>\n        dest: \/etc\/security\/limits.d\/99-babelbird.conf<br \/>\n        mode: &#8216;0644&#8217;<br \/>\n      when: ansible_facts.distribution == &#8220;Ubuntu&#8221;<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u5b89\u5168\u52a0\u56fa<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u7981\u7528\u4e0d\u5fc5\u8981\u7684\u670d\u52a1<br \/>\n      systemd:<br \/>\n        name: &#8220;{{ item }}&#8221;<br \/>\n        state: stopped<br \/>\n        enabled: false<br \/>\n      loop:<br \/>\n        &#8211; postfix      # \u90ae\u4ef6\u670d\u52a1\uff0c\u4e0d\u9700\u8981<br \/>\n        &#8211; rpcbind      # RPC\u670d\u52a1\uff0c\u4e0d\u9700\u8981<br \/>\n      failed_when: false  # \u5982\u679c\u670d\u52a1\u4e0d\u5b58\u5728\uff0c\u8df3\u8fc7\u4e0d\u62a5\u9519<\/p>\n<p>    &#8211; name: \u914d\u7f6eSSH\u670d\u52a1\uff08\u5b89\u5168\u52a0\u56fa\uff09<br \/>\n      blockinfile:<br \/>\n        path: \/etc\/ssh\/sshd_config<br \/>\n        marker: &#8220;# {mark} ANSIBLE MANAGED &#8211; babelbird&#8221;<br \/>\n        block: |<br \/>\n          # \u7981\u7528\u5bc6\u7801\u767b\u5f55\uff08\u5fc5\u987b\u4f7f\u7528\u5bc6\u94a5\uff09<br \/>\n          PasswordAuthentication no<br \/>\n          # \u7981\u7528\u7a7a\u5bc6\u7801<br \/>\n          PermitEmptyPasswords no<br \/>\n          # \u7981\u7528root\u767b\u5f55\uff08\u901a\u8fc7deploy\u7528\u6237sudo\uff09<br \/>\n          PermitRootLogin no<br \/>\n          # \u7981\u7528X11\u8f6c\u53d1<br \/>\n          X11Forwarding no<br \/>\n          # \u6700\u5927\u767b\u5f55\u5c1d\u8bd5\u6b21\u6570<br \/>\n          MaxAuthTries 3<br \/>\n          # \u7981\u7528DNS\u53cd\u5411\u89e3\u6790\uff08\u52a0\u901fSSH\u8fde\u63a5\uff09<br \/>\n          UseDNS no<br \/>\n          # SSH\u534f\u8bae\u7248\u672c<br \/>\n          Protocol 2<br \/>\n      notify: restart sshd<\/p>\n<p>    &#8211; name: \u914d\u7f6e\u9632\u706b\u5899\uff08\u5982\u679c\u5f00\u542f\uff09<br \/>\n      ufw:<br \/>\n        state: enabled<br \/>\n        policy: deny<br \/>\n      when:<br \/>\n        &#8211; ansible_facts[&#8216;distribution&#8217;] == &#8216;Ubuntu&#8217;<br \/>\n        &#8211; ansible_os_family == &#8216;Debian&#8217;<br \/>\n      failed_when: false<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u5e38\u7528\u5de5\u5177\u5b89\u88c5<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u5b89\u88c5\u57fa\u7840\u5de5\u5177\uff08CentOS\/RHEL\u7cfb\uff09<br \/>\n      yum:<br \/>\n        name:<br \/>\n          &#8211; vim<br \/>\n          &#8211; wget<br \/>\n          &#8211; curl<br \/>\n          &#8211; net-tools<br \/>\n          &#8211; tcpdump<br \/>\n          &#8211; htop<br \/>\n          &#8211; iotop<br \/>\n          &#8211; strace<br \/>\n          &#8211; lsof<br \/>\n          &#8211; rsync<br \/>\n          &#8211; git<br \/>\n          &#8211; jq<br \/>\n          &#8211; unzip<br \/>\n          &#8211; bc<br \/>\n          &#8211; sysstat<br \/>\n          &#8211; iotop<br \/>\n          &#8211; dstat<br \/>\n        state: present<br \/>\n      when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;CentOS&#8217;, &#8216;Rocky&#8217;, &#8216;AlmaLinux&#8217;]<\/p>\n<p>    &#8211; name: \u5b89\u88c5\u57fa\u7840\u5de5\u5177\uff08Debian\/Ubuntu\u7cfb\uff09<br \/>\n      apt:<br \/>\n        name:<br \/>\n          &#8211; vim<br \/>\n          &#8211; wget<br \/>\n          &#8211; curl<br \/>\n          &#8211; net-tools<br \/>\n          &#8211; tcpdump<br \/>\n          &#8211; htop<br \/>\n          &#8211; iotop<br \/>\n          &#8211; strace<br \/>\n          &#8211; lsof<br \/>\n          &#8211; rsync<br \/>\n          &#8211; git<br \/>\n          &#8211; jq<br \/>\n          &#8211; unzip<br \/>\n          &#8211; bc<br \/>\n          &#8211; sysstat<br \/>\n          &#8211; dstat<br \/>\n        state: present<br \/>\n        update_cache: yes<br \/>\n      when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # Docker\u73af\u5883\uff08\u5982\u679c\u9700\u8981\uff09<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u68c0\u67e5\u662f\u5426\u9700\u8981\u5b89\u88c5Docker<br \/>\n      set_fact:<br \/>\n        install_docker: &#8220;{{ &#8216;docker&#8217; in group_names or &#8216;k8s&#8217; in group_names }}&#8221;<\/p>\n<p>    &#8211; name: \u9a8c\u8bc1\u521d\u59cb\u5316\u7ed3\u679c<br \/>\n      assert:<br \/>\n        that:<br \/>\n          &#8211; ansible_facts[&#8216;Hostname&#8217;] == inventory_hostname<br \/>\n          &#8211; ansible_facts[&#8216;date_time.tz&#8217;] == timezone<br \/>\n        quiet: true<br \/>\n      register: init_check<\/p>\n<p>    &#8211; name: \u8f93\u51fa\u521d\u59cb\u5316\u7ed3\u679c<br \/>\n      debug:<br \/>\n        msg: |<br \/>\n          \u2705 \u670d\u52a1\u5668\u521d\u59cb\u5316\u5b8c\u6210<br \/>\n          \u4e3b\u673a\u540d: {{ inventory_hostname }}<br \/>\n          IP\u5730\u5740: {{ ansible_facts[&#8216;default_ipv4&#8217;][&#8216;address&#8217;] }}<br \/>\n          \u64cd\u4f5c\u7cfb\u7edf: {{ ansible_facts[&#8216;distribution&#8217;] }} {{ ansible_facts[&#8216;distribution_version&#8217;] }}<br \/>\n          \u65f6\u533a: {{ ansible_facts[&#8216;date_time.tz&#8217;] }}<br \/>\n          Docker\u7248\u672c: {{ ansible_facts[&#8216;packages&#8217;][&#8216;docker&#8217;] | default(&#8216;\u672a\u5b89\u88c5&#8217;) }}<br \/>\n          \u5185\u6838\u7248\u672c: {{ ansible_facts[&#8216;kernel&#8217;] }}<\/p>\n<p>  handlers:<br \/>\n    &#8211; name: restart chronyd<br \/>\n      service:<br \/>\n        name: chronyd<br \/>\n        state: restarted<\/p>\n<p>    &#8211; name: restart sshd<br \/>\n      service:<br \/>\n        name: sshd<br \/>\n        state: restarted<br \/>\n&#8220;`<\/p>\n<p>### 3.2 \u5e94\u7528\u90e8\u7f72Playbook<\/p>\n<p>&#8220;`yaml<br \/>\n# playbooks\/deploy\/babelbird-app.yml<br \/>\n&#8212;<br \/>\n# \u7528\u9014\uff1a\u5df4\u522b\u9e1f\u5e94\u7528\u7684\u5168\u91cf\u90e8\u7f72\u3001\u5347\u7ea7\u3001\u56de\u6eda<br \/>\n# \u4f7f\u7528\u573a\u666f\uff1a<br \/>\n#   &#8211; \u65b0\u96c6\u7fa4\u521d\u59cb\u5316\u90e8\u7f72: ansible-playbook babelbird-app.yml -e action=deploy<br \/>\n#   &#8211; \u7248\u672c\u5347\u7ea7: ansible-playbook babelbird-app.yml -e action=upgrade -e version=2.3.1<br \/>\n#   &#8211; \u56de\u6eda: ansible-playbook babelbird-app.yml -e action=rollback -e version=2.3.0<br \/>\n#   &#8211; \u914d\u7f6e\u53d8\u66f4: ansible-playbook babelbird-app.yml -e action=config-sync<\/p>\n<p>&#8211; name: \u5df4\u522b\u9e1f\u5e94\u7528\u90e8\u7f72<br \/>\n  hosts: k8s_workers<br \/>\n  become: true<br \/>\n  gather_facts: true<\/p>\n<p>  vars:<br \/>\n    # \u5e94\u7528\u57fa\u7840\u914d\u7f6e<br \/>\n    app_name: babelbird<br \/>\n    app_user: babelbird<br \/>\n    app_group: babelbird<br \/>\n    app_install_dir: \/opt\/babelbird<br \/>\n    app_config_dir: \/etc\/babelbird<br \/>\n    app_log_dir: \/var\/log\/babelbird<br \/>\n    app_data_dir: \/data\/babelbird<\/p>\n<p>    # \u9ed8\u8ba4\u7248\u672c\uff08\u53ef\u901a\u8fc7\u547d\u4ee4\u884c\u8986\u76d6\uff09<br \/>\n    version: &#8220;{{ babelbird_version | default(&#8216;2.3.0&#8217;) }}&#8221;<\/p>\n<p>    # Docker\u914d\u7f6e<br \/>\n    docker_image: registry.babelbird.com\/babelbird\/app:{{ version }}<br \/>\n    docker_pull_policy: Always<\/p>\n<p>    # K8s\u914d\u7f6e<br \/>\n    k8s_namespace: babelbird-app<br \/>\n    k8s_replicas: 3<\/p>\n<p>    # \u6570\u636e\u5e93\u914d\u7f6e\uff08\u901a\u8fc7Vault\u6216\u73af\u5883\u53d8\u91cf\u6ce8\u5165\uff09<br \/>\n    db_host: &#8220;{{ groups[&#8216;database_nodes&#8217;] | map(&#8216;extract&#8217;, hostvars, &#8216;ansible_host&#8217;) | first }}&#8221;<br \/>\n    db_port: 5432<br \/>\n    db_name: babelbird<br \/>\n    # \u6ce8\u610f\uff1a\u5bc6\u7801\u4e0d\u5e94\u8be5\u5199\u5728\u8fd9\u91cc\uff0c\u5e94\u8be5\u7528ansible-vault\u52a0\u5bc6\u6216\u4ece\u5916\u90e8\u83b7\u53d6<br \/>\n    # db_password: &#8220;CHANGE_ME&#8221;<\/p>\n<p>  tasks:<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u51c6\u5907\u5de5\u4f5c\uff1a\u521b\u5efa\u7528\u6237\u3001\u76ee\u5f55\u7ed3\u6784<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u521b\u5efa\u5e94\u7528\u7528\u6237<br \/>\n      user:<br \/>\n        name: &#8220;{{ app_user }}&#8221;<br \/>\n        group: &#8220;{{ app_group }}&#8221;<br \/>\n        system: true<br \/>\n        shell: \/sbin\/nologin<br \/>\n        create_home: false<br \/>\n        comment: &#8220;BabelBird Application User&#8221;<\/p>\n<p>    &#8211; name: \u521b\u5efa\u76ee\u5f55\u7ed3\u6784<br \/>\n      file:<br \/>\n        path: &#8220;{{ item }}&#8221;<br \/>\n        state: directory<br \/>\n        owner: &#8220;{{ app_user }}&#8221;<br \/>\n        group: &#8220;{{ app_group }}&#8221;<br \/>\n        mode: &#8216;0755&#8217;<br \/>\n      loop:<br \/>\n        &#8211; &#8220;{{ app_install_dir }}&#8221;<br \/>\n        &#8211; &#8220;{{ app_config_dir }}&#8221;<br \/>\n        &#8211; &#8220;{{ app_log_dir }}&#8221;<br \/>\n        &#8211; &#8220;{{ app_data_dir }}&#8221;<br \/>\n        &#8211; &#8220;{{ app_data_dir }}\/uploads&#8221;<br \/>\n        &#8211; &#8220;{{ app_data_dir }}\/cache&#8221;<br \/>\n        &#8211; &#8220;{{ app_data_dir }}\/temp&#8221;<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u4e0b\u8f7d\/\u62c9\u53d6\u65b0\u7248\u672c\u955c\u50cf<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u767b\u5f55\u79c1\u6709\u955c\u50cf\u4ed3\u5e93<br \/>\n      docker_login:<br \/>\n        registry: &#8220;{{ docker_registry }}&#8221;<br \/>\n        username: &#8220;{{ docker_registry_username }}&#8221;<br \/>\n        password: &#8220;{{ docker_registry_password }}&#8221;<\/p>\n<p>    &#8211; name: \u62c9\u53d6\u5e94\u7528\u955c\u50cf\uff08\u5982\u679c\u672c\u5730\u4e0d\u5b58\u5728\uff09<br \/>\n      docker_image:<br \/>\n        name: &#8220;{{ docker_image }}&#8221;<br \/>\n        pull: true<br \/>\n        source: pull<br \/>\n        force_source: true<br \/>\n      register: image_pull_result<br \/>\n      until: image_pull_result is succeeded<br \/>\n      retries: 3<br \/>\n      delay: 30<br \/>\n      when: docker_pull_policy == &#8216;Always&#8217; or not (docker_image is regex(&#8216;.*:latest&#8217;))<\/p>\n<p>    &#8211; name: \u8bb0\u5f55\u5f53\u524d\u8fd0\u884c\u7248\u672c\uff08\u7528\u4e8e\u56de\u6eda\u5224\u65ad\uff09<br \/>\n      shell: |<br \/>\n        kubectl get deployment babelbird-api -n {{ k8s_namespace }} -o jsonpath='{.spec.template.spec.containers[0].image}&#8217; 2>\/dev\/null || echo &#8220;not-deployed&#8221;<br \/>\n      register: current_image<br \/>\n      failed_when: false<br \/>\n      changed_when: false<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u751f\u6210\u914d\u7f6e\u6587\u4ef6<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u751f\u6210\u5e94\u7528\u914d\u7f6e\u6587\u4ef6<br \/>\n      template:<br \/>\n        src: templates\/babelbird\/config.yaml.j2<br \/>\n        dest: &#8220;{{ app_config_dir }}\/config.yaml&#8221;<br \/>\n        owner: &#8220;{{ app_user }}&#8221;<br \/>\n        group: &#8220;{{ app_group }}&#8221;<br \/>\n        mode: &#8216;0600&#8217;<br \/>\n      notify: reload babelbird<br \/>\n      vars:<br \/>\n        current_version: &#8220;{{ current_image.stdout | default(&#8216;not-deployed&#8217;) }}&#8221;<\/p>\n<p>    &#8211; name: \u751f\u6210Kubernetes Deployment\u6e05\u5355<br \/>\n      template:<br \/>\n        src: templates\/babelbird\/deployment.yaml.j2<br \/>\n        dest: \/tmp\/babelbird-deployment-{{ version }}.yaml<br \/>\n        mode: &#8216;0644&#8217;<\/p>\n<p>    &#8211; name: \u751f\u6210Kubernetes Service\u6e05\u5355<br \/>\n      template:<br \/>\n        src: templates\/babelbird\/service.yaml.j2<br \/>\n        dest: \/tmp\/babelbird-service-{{ version }}.yaml<br \/>\n        mode: &#8216;0644&#8217;<\/p>\n<p>    &#8211; name: \u751f\u6210Kubernetes HPA\u914d\u7f6e<br \/>\n      template:<br \/>\n        src: templates\/babelbird\/hpa.yaml.j2<br \/>\n        dest: \/tmp\/babelbird-hpa-{{ version }}.yaml<br \/>\n        mode: &#8216;0644&#8217;<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u6267\u884c\u90e8\u7f72\u52a8\u4f5c\uff08\u6839\u636eaction\u53d8\u91cf\uff09<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: &#8220;[DEPLOY] \u5168\u91cf\u90e8\u7f72\u65b0\u7248\u672c&#8221;<br \/>\n      when: action == &#8216;deploy&#8217; or action == &#8216;upgrade&#8217;<br \/>\n      block:<br \/>\n        &#8211; name: \u90e8\u7f72\u5e94\u7528\u5230K8s<br \/>\n          shell: |<br \/>\n            kubectl apply -f \/tmp\/babelbird-deployment-{{ version }}.yaml<br \/>\n            kubectl apply -f \/tmp\/babelbird-service-{{ version }}.yaml<br \/>\n            kubectl apply -f \/tmp\/babelbird-hpa-{{ version }}.yaml<br \/>\n          register: k8s_deploy_result<\/p>\n<p>        &#8211; name: \u7b49\u5f85Deployment\u5c31\u7eea<br \/>\n          shell: |<br \/>\n            kubectl rollout status deployment\/babelbird-api -n {{ k8s_namespace }} &#8211;timeout=300s<br \/>\n          register: rollout_status<br \/>\n          failed_when: &#8220;&#8216;deployment \\&#8221;babelbird-api\\&#8221; successfully rolled out&#8217; not in rollout_status.stdout&#8221;<\/p>\n<p>        &#8211; name: \u9a8c\u8bc1Pod\u5065\u5eb7\u72b6\u6001<br \/>\n          shell: |<br \/>\n            kubectl get pods -n {{ k8s_namespace }} -l app=babelbird-api -o wide<br \/>\n          register: pod_status<\/p>\n<p>        &#8211; name: \u8bb0\u5f55\u90e8\u7f72\u5386\u53f2\uff08\u7528\u4e8e\u56de\u6eda\uff09<br \/>\n          lineinfile:<br \/>\n            path: &#8220;{{ app_install_dir }}\/.deploy_history&#8221;<br \/>\n            line: &#8220;{{ ansible_date_time.epoch }} {{ version }} {{ ansible_user }} {{ ansible_host }}&#8221;<br \/>\n            create: true<br \/>\n            mode: &#8216;0644&#8217;<\/p>\n<p>        &#8211; name: \u8f93\u51fa\u90e8\u7f72\u7ed3\u679c<br \/>\n          debug:<br \/>\n            msg: |<br \/>\n              \u2705 \u90e8\u7f72\u6210\u529f<br \/>\n              \u7248\u672c: {{ version }}<br \/>\n              \u955c\u50cf: {{ docker_image }}<br \/>\n              \u90e8\u7f72\u65f6\u95f4: {{ ansible_date_time.iso8601 }}<br \/>\n              \u90e8\u7f72\u4eba: {{ ansible_user }}<\/p>\n<p>    &#8211; name: &#8220;[ROLLBACK] \u56de\u6eda\u5230\u6307\u5b9a\u7248\u672c&#8221;<br \/>\n      when: action == &#8216;rollback&#8217;<br \/>\n      block:<br \/>\n        &#8211; name: \u6267\u884c\u56de\u6eda<br \/>\n          shell: |<br \/>\n            kubectl rollout undo deployment\/babelbird-api -n {{ k8s_namespace }} &#8211;to-revision={{ rollback_revision | default(1) }}<br \/>\n          register: rollback_result<br \/>\n          failed_when: false<\/p>\n<p>        &#8211; name: \u7b49\u5f85\u56de\u6eda\u5b8c\u6210<br \/>\n          shell: |<br \/>\n            kubectl rollout status deployment\/babelbird-api -n {{ k8s_namespace }} &#8211;timeout=300s<br \/>\n          register: rollback_status<br \/>\n          when: rollback_result.rc == 0<\/p>\n<p>        &#8211; name: \u8bb0\u5f55\u56de\u6eda\u5386\u53f2<br \/>\n          lineinfile:<br \/>\n            path: &#8220;{{ app_install_dir }}\/.deploy_history&#8221;<br \/>\n            line: &#8220;{{ ansible_date_time.epoch }} ROLLBACK to {{ version }} by {{ ansible_user }} {{ ansible_host }}&#8221;<br \/>\n            create: true<\/p>\n<p>        &#8211; name: \u8f93\u51fa\u56de\u6eda\u7ed3\u679c<br \/>\n          debug:<br \/>\n            msg: |<br \/>\n              {% if rollback_result.rc == 0 %}<br \/>\n              \u2705 \u56de\u6eda\u6210\u529f<br \/>\n              \u56de\u6eda\u5230\u7248\u672c: {{ version }}<br \/>\n              {% else %}<br \/>\n              \u26a0\ufe0f \u56de\u6eda\u6267\u884c\u4f46\u53ef\u80fd\u672a\u5b8c\u5168\u6210\u529f\uff0c\u8bf7\u624b\u52a8\u68c0\u67e5<br \/>\n              {% endif %}<\/p>\n<p>    &#8211; name: &#8220;[CONFIG-SYNC] \u4ec5\u540c\u6b65\u914d\u7f6e\uff08\u4e0d\u91cd\u542fPod\uff09&#8221;<br \/>\n      when: action == &#8216;config-sync&#8217;<br \/>\n      shell: |<br \/>\n        kubectl get configmap babelbird-config -n {{ k8s_namespace }} -o yaml | \\<br \/>\n        kubectl replace -n {{ k8s_namespace }} -f &#8211;<br \/>\n      register: config_sync_result<\/p>\n<p>    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    # \u90e8\u7f72\u540e\u9a8c\u8bc1<br \/>\n    #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n    &#8211; name: \u5065\u5eb7\u68c0\u67e5<br \/>\n      shell: |<br \/>\n        kubectl exec -n {{ k8s_namespace }} \\<br \/>\n          $(kubectl get pods -n {{ k8s_namespace }} -l app=babelbird-api -o jsonpath='{.items[0].metadata.name}&#8217;) \\<br \/>\n          &#8212; curl -s http:\/\/localhost:8080\/api\/health<br \/>\n      register: health_check<br \/>\n      failed_when: false<br \/>\n      changed_when: false<br \/>\n      when: action in [&#8216;deploy&#8217;, &#8216;upgrade&#8217;]<\/p>\n<p>    &#8211; name: \u8f93\u51fa\u6700\u7ec8\u72b6\u6001<br \/>\n      debug:<br \/>\n        msg: |<br \/>\n          ========================<br \/>\n          \u90e8\u7f72\u4efb\u52a1\u5b8c\u6210<br \/>\n          ========================<br \/>\n          \u4e3b\u673a: {{ inventory_hostname }}<br \/>\n          \u7248\u672c: {{ version }}<br \/>\n          \u955c\u50cf: {{ docker_image }}<br \/>\n          \u52a8\u4f5c: {{ action }}<br \/>\n          \u5065\u5eb7\u72b6\u6001: {{ health_check.stdout | default(&#8216;\u672a\u6267\u884c&#8217;) }}<br \/>\n          ========================<\/p>\n<p>  handlers:<br \/>\n    &#8211; name: reload babelbird<br \/>\n      shell: |<br \/>\n        kubectl rollout restart deployment\/babelbird-api -n {{ k8s_namespace }}<br \/>\n      listen: &#8220;reload babelbird&#8221;<br \/>\n&#8220;`<\/p>\n<p>### 3.3 \u6838\u5fc3Role\u793a\u4f8b\uff1aDocker\u5b89\u88c5\u4e0e\u914d\u7f6e<\/p>\n<p>&#8220;`yaml<br \/>\n# roles\/docker\/tasks\/main.yml<br \/>\n&#8212;<br \/>\n# \u7528\u9014\uff1a\u7edf\u4e00\u5b89\u88c5\u548c\u914d\u7f6eDocker\uff0c\u786e\u4fdd\u6240\u6709\u670d\u52a1\u5668Docker\u7248\u672c\u548c\u884c\u4e3a\u4e00\u81f4<\/p>\n<p>&#8211; name: \u68c0\u67e5Docker\u662f\u5426\u5df2\u5b89\u88c5<br \/>\n  command: docker &#8211;version<br \/>\n  register: docker_check<br \/>\n  failed_when: false<br \/>\n  changed_when: false<\/p>\n<p>&#8211; name: \u83b7\u53d6\u5df2\u5b89\u88c5Docker\u7248\u672c<br \/>\n  set_fact:<br \/>\n    docker_installed: &#8220;{{ docker_check.rc == 0 }}&#8221;<br \/>\n    docker_current_version: &#8220;{{ docker_check.stdout | regex_replace(&#8216;Docker version &#8216;, &#8221;) | regex_replace(&#8216;,.*&#8217;, &#8221;) if docker_check.rc == 0 else &#8221; }}&#8221;<\/p>\n<p>&#8211; name: \u786e\u5b9a\u76ee\u6807Docker\u7248\u672c<br \/>\n  set_fact:<br \/>\n    docker_target_version: &#8220;{{ docker_version | default(&#8216;24.0.7&#8217;) }}&#8221;<\/p>\n<p>&#8211; name: \u5b89\u88c5\u4f9d\u8d56\u5305\uff08CentOS\/RHEL\uff09<br \/>\n  yum:<br \/>\n    name:<br \/>\n      &#8211; yum-utils<br \/>\n      &#8211; device-mapper-persistent-data<br \/>\n      &#8211; lvm2<br \/>\n    state: present<br \/>\n  when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;CentOS&#8217;, &#8216;Rocky&#8217;, &#8216;AlmaLinux&#8217;]<\/p>\n<p>&#8211; name: \u5b89\u88c5\u4f9d\u8d56\u5305\uff08Debian\/Ubuntu\uff09<br \/>\n  apt:<br \/>\n    name:<br \/>\n      &#8211; apt-transport-https<br \/>\n      &#8211; ca-certificates<br \/>\n      &#8211; curl<br \/>\n      &#8211; gnupg<br \/>\n      &#8211; lsb-release<br \/>\n    state: present<br \/>\n    update_cache: yes<br \/>\n  when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>&#8211; name: \u6dfb\u52a0Docker\u5b98\u65b9GPG\u5bc6\u94a5\uff08Debian\/Ubuntu\uff09<br \/>\n  apt_key:<br \/>\n    url: https:\/\/download.docker.com\/linux\/{{ ansible_facts[&#8216;distribution&#8217;] | lower }}\/gpg<br \/>\n    state: present<br \/>\n  when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>&#8211; name: \u6dfb\u52a0Docker\u4ed3\u5e93\uff08Debian\/Ubuntu\uff09<br \/>\n  apt_repository:<br \/>\n    repo: &#8220;deb [arch={{ ansible_facts[&#8216;architecture&#8217;] }}] https:\/\/download.docker.com\/linux\/{{ ansible_facts[&#8216;distribution&#8217;] | lower }} {{ ansible_facts[&#8216;distribution_release&#8217;] }} stable&#8221;<br \/>\n    state: present<br \/>\n  when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>&#8211; name: \u5b89\u88c5Docker\uff08Debian\/Ubuntu\uff09<br \/>\n  apt:<br \/>\n    name:<br \/>\n      &#8211; docker-ce={{ docker_target_version }}*<br \/>\n      &#8211; docker-ce-cli={{ docker_target_version }}*<br \/>\n      &#8211; containerd.io<br \/>\n      &#8211; docker-buildx-plugin<br \/>\n      &#8211; docker-compose-plugin<br \/>\n    state: present<br \/>\n    update_cache: yes<br \/>\n  when: ansible_facts[&#8216;distribution&#8217;] in [&#8216;Debian&#8217;, &#8216;Ubuntu&#8217;]<\/p>\n<p>&#8211; name: \u914d\u7f6eDocker daemon\uff08daemon.json\uff09<br \/>\n  block:<br \/>\n    &#8211; name: \u521b\u5efaDocker\u914d\u7f6e\u76ee\u5f55<br \/>\n      file:<br \/>\n        path: \/etc\/docker<br \/>\n        state: directory<br \/>\n        mode: &#8216;0755&#8217;<\/p>\n<p>    &#8211; name: \u914d\u7f6eDocker daemon\u53c2\u6570<br \/>\n      template:<br \/>\n        src: templates\/docker\/daemon.json.j2<br \/>\n        dest: \/etc\/docker\/daemon.json<br \/>\n        mode: &#8216;0644&#8217;<br \/>\n  notify: restart docker<\/p>\n<p>    &#8211; name: \u914d\u7f6eDocker\u65e5\u5fd7\u9a71\u52a8\uff08\u907f\u514d\u65e5\u5fd7\u6491\u7206\u78c1\u76d8\uff09<br \/>\n      blockinfile:<br \/>\n        path: \/etc\/docker\/daemon.json<br \/>\n        marker: &#8220;# {mark} ANSIBLE MANAGED &#8211; log driver&#8221;<br \/>\n        block: |<br \/>\n          &#8220;log-driver&#8221;: &#8220;json-file&#8221;,<br \/>\n          &#8220;log-opts&#8221;: {<br \/>\n            &#8220;max-size&#8221;: &#8220;100m&#8221;,<br \/>\n            &#8220;max-file&#8221;: &#8220;3&#8221;,<br \/>\n            &#8220;compress&#8221;: &#8220;true&#8221;<br \/>\n          }<br \/>\n      when: docker_log_driver == &#8216;json-file&#8217;<br \/>\n      notify: restart docker<\/p>\n<p>  &#8211; name: \u542f\u52a8\u5e76\u542f\u7528Docker<br \/>\n    service:<br \/>\n      name: docker<br \/>\n      state: started<br \/>\n      enabled: true<\/p>\n<p>  &#8211; name: \u5c06deploy\u7528\u6237\u52a0\u5165docker\u7ec4\uff08\u514dsudo\uff09<br \/>\n    user:<br \/>\n      name: &#8220;{{ ansible_user }}&#8221;<br \/>\n      groups: docker<br \/>\n      append: yes<\/p>\n<p>  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  # Docker\u5b58\u50a8\u9a71\u52a8\u4f18\u5316<br \/>\n  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  &#8211; name: \u68c0\u67e5\u5f53\u524d\u5b58\u50a8\u9a71\u52a8<br \/>\n    command: docker info &#8211;format &#8216;{{.Driver}}&#8217;<br \/>\n    register: storage_driver<br \/>\n    changed_when: false<\/p>\n<p>  &#8211; name: \u914d\u7f6e\u5b58\u50a8\u9a71\u52a8\uff08overlay2\u63a8\u8350\uff09<br \/>\n    lineinfile:<br \/>\n      path: \/etc\/docker\/daemon.json<br \/>\n      regexp: &#8216;&#8221;storage-driver&#8221;&#8216;<br \/>\n      line: &#8216;&#8221;storage-driver&#8221;: &#8220;overlay2&#8243;&#8216;<br \/>\n      create: true<br \/>\n    when: storage_driver.stdout != &#8216;overlay2&#8217;<br \/>\n    notify: restart docker<\/p>\n<p>  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  # \u914d\u7f6e\u955c\u50cf\u52a0\u901f\u5668\uff08\u5982\u6709\uff09<br \/>\n  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  &#8211; name: \u914d\u7f6e\u955c\u50cf\u52a0\u901f\u5668<br \/>\n    blockinfile:<br \/>\n      path: \/etc\/docker\/daemon.json<br \/>\n      marker: &#8220;# {mark} ANSIBLE MANAGED &#8211; registry mirror&#8221;<br \/>\n      block: |<br \/>\n        &#8220;registry-mirrors&#8221;: [&#8220;https:\/\/mirror.babelbird.com&#8221;]<br \/>\n    when: docker_mirror_enabled | default(false)<br \/>\n    notify: restart docker<\/p>\n<p>  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  # \u9a8c\u8bc1\u5b89\u88c5\u7ed3\u679c<br \/>\n  #&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n  &#8211; name: \u9a8c\u8bc1Docker\u7248\u672c<br \/>\n    command: docker &#8211;version<br \/>\n    register: final_docker_version<\/p>\n<p>  &#8211; name: \u9a8c\u8bc1Docker\u670d\u52a1\u72b6\u6001<br \/>\n    service:<br \/>\n      name: docker<br \/>\n      state: started<br \/>\n    register: docker_service_status<\/p>\n<p>  &#8211; name: \u9a8c\u8bc1\u5bb9\u5668\u8fd0\u884c\u80fd\u529b<br \/>\n    command: docker run &#8211;rm alpine echo &#8220;Docker is working&#8221;<br \/>\n    register: docker_test<br \/>\n    retries: 3<br \/>\n    delay: 5<br \/>\n    until: docker_test.rc == 0<\/p>\n<p>  &#8211; name: \u8f93\u51faDocker\u5b89\u88c5\u7ed3\u679c<br \/>\n    debug:<br \/>\n      msg: |<br \/>\n        \u2705 Docker\u5b89\u88c5\u5b8c\u6210<br \/>\n        \u7248\u672c: {{ final_docker_version.stdout }}<br \/>\n        \u5b58\u50a8\u9a71\u52a8: {{ storage_driver.stdout }}<br \/>\n        \u670d\u52a1\u72b6\u6001: {{ &#8216;running&#8217; if docker_service_status.state == &#8216;started&#8217; else &#8216;stopped&#8217; }}<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<p>## \u56db\u3001CI\/CD\u6d41\u6c34\u7ebf\uff1a\u4ece\u4ee3\u7801\u63d0\u4ea4\u5230\u81ea\u52a8\u90e8\u7f72<\/p>\n<p>### 4.1 \u4e3a\u4ec0\u4e48\u9700\u8981CI\/CD<\/p>\n<p>\u6ca1\u6709CI\/CD\u65f6\uff0c\u5df4\u522b\u9e1f\u7684\u53d1\u5e03\u6d41\u7a0b\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>&#8220;`<br \/>\n\u5f00\u53d1\u63d0\u4ea4\u4ee3\u7801 \u2192 \u6784\u5efa\u811a\u672c\u624b\u52a8\u6267\u884c \u2192 \u6d4b\u8bd5\u73af\u5883\u9a8c\u8bc1 \u2192 \u751f\u4ea7\u53d1\u5e03\u7533\u8bf7 \u2192 \u624b\u5de5\u90e8\u7f72<br \/>\n&#8220;`<\/p>\n<p>\u95ee\u9898\uff1a<br \/>\n&#8211; \u4eba\u5de5\u64cd\u4f5c\u5bb9\u6613\u51fa\u9519\uff08\u6572\u9519\u7248\u672c\u53f7\u3001\u6f0f\u6389\u67d0\u4e2a\u6b65\u9aa4\uff09<br \/>\n&#8211; \u6d4b\u8bd5\u7ed3\u679c\u6ca1\u6709\u8bb0\u5f55\uff08\u8c01\u6d4b\u7684\u3001\u4ec0\u4e48\u65f6\u5019\u6d4b\u7684\u3001\u6d4b\u4e86\u54ea\u4e9b\u7528\u4f8b\uff09<br \/>\n&#8211; \u56de\u6eda\u9760\u624b\u5de5\uff08\u534a\u591c3\u70b9\u624b\u5fd9\u811a\u4e71\u6572\u547d\u4ee4\uff09<br \/>\n&#8211; \u53d1\u5e03\u8fc7\u7a0b\u6ca1\u6709\u5ba1\u8ba1\uff08\u8c01\u53d1\u5e03\u7684\u3001\u4ec0\u4e48\u65f6\u95f4\u3001\u54ea\u4e2a\u7248\u672c\uff09<\/p>\n<p>\u6709\u4e86CI\/CD\u540e\uff1a<\/p>\n<p>&#8220;`<br \/>\n\u5f00\u53d1\u63d0\u4ea4\u4ee3\u7801 \u2192 \u81ea\u52a8\u6784\u5efa \u2192 \u81ea\u52a8\u5355\u5143\u6d4b\u8bd5 \u2192 \u81ea\u52a8\u96c6\u6210\u6d4b\u8bd5 \u2192 \u81ea\u52a8\u90e8\u7f72\u6d4b\u8bd5\u73af\u5883<br \/>\n\u2192 \u4eba\u5de5\u5ba1\u6279\uff08\u53ef\u9009\uff09 \u2192 \u81ea\u52a8\u90e8\u7f72\u9884\u751f\u4ea7 \u2192 \u81ea\u52a8\u90e8\u7f72\u751f\u4ea7 \u2192 \u81ea\u52a8\u9a8c\u8bc1<br \/>\n&#8220;`<\/p>\n<p>### 4.2 GitLab CI\/CD\u914d\u7f6e<\/p>\n<p>&#8220;`yaml<br \/>\n# .gitlab-ci.yml<br \/>\n# \u5df4\u522b\u9e1fCI\/CD\u4e3b\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>stages:<br \/>\n  &#8211; build<br \/>\n  &#8211; test<br \/>\n  &#8211; deploy-staging<br \/>\n  &#8211; deploy-production<br \/>\n  &#8211; verify<\/p>\n<p>variables:<br \/>\n  # Docker\u914d\u7f6e<br \/>\n  DOCKER_DRIVER: overlay2<br \/>\n  DOCKER_TLS_CERTDIR: &#8220;\/certs&#8221;<br \/>\n  # \u955c\u50cf\u4ed3\u5e93<br \/>\n  REGISTRY: registry.babelbird.com<br \/>\n  REGISTRY_IMAGE: ${REGISTRY}\/babelbird\/app<br \/>\n  # Helm\u914d\u7f6e<br \/>\n  HELM_VERSION: &#8220;3.13.0&#8221;<br \/>\n  # K8s\u914d\u7f6e<br \/>\n  K8S_NAMESPACE_STAGING: babelbird-staging<br \/>\n  K8S_NAMESPACE_PROD: babelbird-app<\/p>\n<p>#===============================================================<br \/>\n# \u5168\u5c40\u914d\u7f6e<br \/>\n#===============================================================<br \/>\nimage: docker:24-dind<\/p>\n<p>before_script:<br \/>\n  &#8211; docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD $REGISTRY<br \/>\n  &#8211; export HELM_VERSION=&#8221;3.13.0&#8243;<br \/>\n  &#8211; curl -fsSL https:\/\/get.helm.sh\/helm-v${HELM_VERSION}-linux-amd64.tar.gz | tar -xz -C \/tmp<br \/>\n  &#8211; mv \/tmp\/linux-amd64\/helm \/usr\/local\/bin\/helm &#038;&#038; chmod +x \/usr\/local\/bin\/helm<\/p>\n<p>#===============================================================<br \/>\n# \u6784\u5efa\u9636\u6bb5<br \/>\n#===============================================================<br \/>\nbuild:docker:<br \/>\n  stage: build<br \/>\n  only:<br \/>\n    &#8211; develop<br \/>\n    &#8211; master<br \/>\n    &#8211; tags<br \/>\n    &#8211; \/^release\\\/.*$\/<br \/>\n  script:<br \/>\n    # \u6784\u5efa\u540e\u7aef\u5e94\u7528<br \/>\n    &#8211; echo &#8220;Building backend application&#8230;&#8221;<br \/>\n    &#8211; docker build<br \/>\n        &#8211;build-arg BUILD_VERSION=${CI_COMMIT_SHORT_SHA}<br \/>\n        &#8211;build-arg BUILD_TIME=$(date -u +&#8221;%Y-%m-%dT%H:%M:%SZ&#8221;)<br \/>\n        &#8211;build-arg GIT_COMMIT=${CI_COMMIT_SHA}<br \/>\n        -t ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}<br \/>\n        -t ${REGISTRY_IMAGE}:${CI_COMMIT_REF_NAME}<br \/>\n        -t ${REGISTRY_IMAGE}:latest<br \/>\n        &#8211;target production<br \/>\n        &#8211;push<br \/>\n        .<br \/>\n    # \u63a8\u9001\u540e\u8bb0\u5f55\u7248\u672c\u4fe1\u606f<br \/>\n    &#8211; echo &#8220;${CI_COMMIT_SHORT_SHA}&#8221; > version.txt<br \/>\n    &#8211; docker buildx build &#8211;push &#8211;platforms linux\/amd64,linux\/arm64 -t ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA} .<br \/>\n  artifacts:<br \/>\n    paths:<br \/>\n      &#8211; version.txt<br \/>\n    expire_in: 1 week<br \/>\n  tags:<br \/>\n    &#8211; build<br \/>\n  timeout: 30m<\/p>\n<p>#===============================================================<br \/>\n# \u6d4b\u8bd5\u9636\u6bb5<br \/>\n#===============================================================<br \/>\ntest:unit:<br \/>\n  stage: test<br \/>\n  image: maven:3.9-eclipse-temurin-17<br \/>\n  script:<br \/>\n    &#8211; mvn clean test -B -Dspring.profiles.active=test<br \/>\n    &#8211; mvn jacoco:report<br \/>\n  coverage: &#8216;\/Total.*?([0-9]{1,3})%\/&#8217;<br \/>\n  artifacts:<br \/>\n    reports:<br \/>\n      junit: target\/surefire-reports\/TEST-*.xml<br \/>\n      coverage_report:<br \/>\n        coverage_format: jacoco<br \/>\n        path: target\/site\/jacoco\/jacoco.xml<br \/>\n  only:<br \/>\n    &#8211; merge_requests<br \/>\n    &#8211; develop<br \/>\n    &#8211; master<br \/>\n  tags:<br \/>\n    &#8211; test<br \/>\n  timeout: 20m<\/p>\n<p>test:integration:<br \/>\n  stage: test<br \/>\n  image: ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}<br \/>\n  services:<br \/>\n    &#8211; postgres:15<br \/>\n    &#8211; redis:7<br \/>\n  script:<br \/>\n    &#8211; echo &#8220;Running integration tests&#8230;&#8221;<br \/>\n    &#8211; mvn verify -B -Pintegration-test<br \/>\n  artifacts:<br \/>\n    reports:<br \/>\n      junit: target\/surefire-reports\/TEST-*.xml<br \/>\n  only:<br \/>\n    &#8211; develop<br \/>\n    &#8211; master<br \/>\n  tags:<br \/>\n    &#8211; test<br \/>\n  timeout: 30m<\/p>\n<p>test:security:<br \/>\n  stage: test<br \/>\n  image: aquasec\/trivy:latest<br \/>\n  script:<br \/>\n    &#8211; trivy image &#8211;exit-code 1 &#8211;severity HIGH,CRITICAL ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}<br \/>\n  allow_failure: true  # \u5b89\u5168\u626b\u63cf\u5931\u8d25\u4e0d\u963b\u6b62\u53d1\u5e03\uff0c\u4f46\u9700\u8981\u4eba\u5de5\u786e\u8ba4<br \/>\n  only:<br \/>\n    &#8211; develop<br \/>\n    &#8211; master<br \/>\n    &#8211; tags<br \/>\n  tags:<br \/>\n    &#8211; test<\/p>\n<p>#===============================================================<br \/>\n# \u90e8\u7f72\u6d4b\u8bd5\u73af\u5883<br \/>\n#===============================================================<br \/>\ndeploy:staging:<br \/>\n  stage: deploy-staging<br \/>\n  environment:<br \/>\n    name: staging<br \/>\n    url: https:\/\/staging.babelbird.com<br \/>\n    on_stop: cleanup:staging<br \/>\n  script:<br \/>\n    &#8211; echo &#8220;Deploying to staging environment&#8230;&#8221;<br \/>\n    # \u51c6\u5907K8s\u914d\u7f6e<br \/>\n    &#8211; kubectl config use-context staging<br \/>\n    # Helm\u5347\u7ea7\u90e8\u7f72<br \/>\n    &#8211; helm upgrade &#8211;install babelbird ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}<br \/>\n        &#8211;namespace ${K8S_NAMESPACE_STAGING}<br \/>\n        &#8211;create-namespace<br \/>\n        &#8211;values helm\/values-staging.yaml<br \/>\n        &#8211;set image.tag=${CI_COMMIT_SHORT_SHA}<br \/>\n        &#8211;set replicaCount=2<br \/>\n        &#8211;wait &#8211;timeout 10m<br \/>\n        &#8211;atomic<br \/>\n        &#8211;cleanup-on-fail<br \/>\n    # \u7b49\u5f85Pod\u5c31\u7eea<br \/>\n    &#8211; kubectl rollout status deployment\/babelbird-app -n ${K8S_NAMESPACE_STAGING} &#8211;timeout=300s<br \/>\n    # \u6267\u884c\u5192\u70df\u6d4b\u8bd5<br \/>\n    &#8211; kubectl exec -n ${K8S_NAMESPACE_STAGING} deploy\/babelbird-app &#8212; curl -sf http:\/\/localhost:8080\/api\/health<br \/>\n  only:<br \/>\n    &#8211; develop<br \/>\n    &#8211; master<br \/>\n  tags:<br \/>\n    &#8211; deploy<br \/>\n  timeout: 15m<\/p>\n<p>#===============================================================<br \/>\n# \u90e8\u7f72\u751f\u4ea7\u73af\u5883\uff08\u9700\u8981\u624b\u52a8\u5ba1\u6279\uff09<br \/>\n#===============================================================<br \/>\ndeploy:production:<br \/>\n  stage: deploy-production<br \/>\n  environment:<br \/>\n    name: production<br \/>\n    url: https:\/\/www.babelbird.com<br \/>\n    on_stop: rollback:production<br \/>\n  script:<br \/>\n    &#8211; echo &#8220;Deploying to production environment&#8230;&#8221;<br \/>\n    &#8211; kubectl config use-context production<br \/>\n    # \u5907\u4efd\u5f53\u524d\u7248\u672c\u4fe1\u606f\uff08\u7528\u4e8e\u56de\u6eda\uff09<br \/>\n    &#8211; kubectl get deployment babelbird-app -n ${K8S_NAMESPACE_PROD} -o jsonpath='{.spec.template.spec.containers[0].image}&#8217; > \/tmp\/current_image.txt<br \/>\n    # Helm\u5347\u7ea7\u90e8\u7f72<br \/>\n    &#8211; helm upgrade &#8211;install babelbird ${REGISTRY_IMAGE}:${CI_COMMIT_SHORT_SHA}<br \/>\n        &#8211;namespace ${K8S_NAMESPACE_PROD}<br \/>\n        &#8211;create-namespace<br \/>\n        &#8211;values helm\/values-production.yaml<br \/>\n        &#8211;set image.tag=${CI_COMMIT_SHORT_SHA}<br \/>\n        &#8211;set replicaCount=5<br \/>\n        &#8211;set hpa.enabled=true<br \/>\n        &#8211;set hpa.minReplicas=3<br \/>\n        &#8211;set hpa.maxReplicas=20<br \/>\n        &#8211;wait &#8211;timeout 15m<br \/>\n        &#8211;atomic<br \/>\n        &#8211;cleanup-on-fail<br \/>\n    # \u7b49\u5f85Pod\u5c31\u7eea<br \/>\n    &#8211; kubectl rollout status deployment\/babelbird-app -n ${K8S_NAMESPACE_PROD} &#8211;timeout=600s<br \/>\n    # \u5065\u5eb7\u68c0\u67e5<br \/>\n    &#8211; kubectl exec -n ${K8S_NAMESPACE_PROD} deploy\/babelbird-app &#8212; curl -sf http:\/\/localhost:8080\/api\/health<br \/>\n    # \u8bb0\u5f55\u90e8\u7f72\u5386\u53f2\u5230Consul KV<br \/>\n    &#8211; consul kv put babelbird\/deploy\/history\/${CI_COMMIT_SHORT_SHA} &#8220;{\\&#8221;timestamp\\&#8221;:\\&#8221;$(date -u)\\&#8221;,\\&#8221;deployer\\&#8221;:\\&#8221;${GITLAB_USER_NAME}\\&#8221;,\\&#8221;commit\\&#8221;:\\&#8221;${CI_COMMIT_SHA}\\&#8221;}&#8221;<br \/>\n  only:<br \/>\n    &#8211; tags<br \/>\n    &#8211; \/^release\\\/.*$\/<br \/>\n  when: manual  # \u624b\u52a8\u89e6\u53d1\uff08\u751f\u4ea7\u73af\u5883\u5fc5\u987b\u4eba\u5de5\u786e\u8ba4\uff09<br \/>\n  tags:<br \/>\n    &#8211; deploy<br \/>\n  timeout: 30m<\/p>\n<p>#===============================================================<br \/>\n# \u9a8c\u8bc1\u9636\u6bb5<br \/>\n#===============================================================<br \/>\nverify:production:<br \/>\n  stage: verify<br \/>\n  script:<br \/>\n    &#8211; echo &#8220;Running post-deployment verification&#8230;&#8221;<br \/>\n    # \u8c03\u7528\u4e1a\u52a1\u5c42\u5065\u5eb7\u68c0\u67e5\u63a5\u53e3<br \/>\n    &#8211; curl -sf https:\/\/www.babelbird.com\/api\/health<br \/>\n    # \u8c03\u7528\u76d1\u63a7\u63a5\u53e3\u83b7\u53d6\u5173\u952e\u6307\u6807<br \/>\n    &#8211; curl -sf https:\/\/www.babelbird.com\/api\/metrics | jq &#8216;.activeUsers&#8217;<br \/>\n    # \u68c0\u67e5Prometheus\u544a\u8b66\u72b6\u6001<br \/>\n    &#8211; curl -sf &#8220;http:\/\/prometheus:9090\/api\/v1\/alerts&#8221; | jq &#8216;.data.alerts | length&#8217;<br \/>\n  only:<br \/>\n    &#8211; tags<br \/>\n    &#8211; \/^release\\\/.*$\/<br \/>\n  tags:<br \/>\n    &#8211; verify<br \/>\n  timeout: 10m<\/p>\n<p>#===============================================================<br \/>\n# \u6e05\u7406\uff08staging\u73af\u5883\u751f\u547d\u5468\u671f\u7ba1\u7406\uff09<br \/>\n#===============================================================<br \/>\ncleanup:staging:<br \/>\n  stage: deploy-staging<br \/>\n  script:<br \/>\n    &#8211; kubectl config use-context staging<br \/>\n    &#8211; helm uninstall babelbird -n ${K8S_NAMESPACE_STAGING} || true<br \/>\n  environment:<br \/>\n    name: staging<br \/>\n    action: stop<br \/>\n  when: manual<br \/>\n  only:<br \/>\n    &#8211; develop<br \/>\n  tags:<br \/>\n    &#8211; deploy<\/p>\n<p>#===============================================================<br \/>\n# \u56de\u6eda\uff08\u751f\u4ea7\u7d27\u6025\u56de\u9000\uff09<br \/>\n#===============================================================<br \/>\nrollback:production:<br \/>\n  stage: deploy-production<br \/>\n  script:<br \/>\n    &#8211; kubectl config use-context production<br \/>\n    &#8211; |<br \/>\n      # \u83b7\u53d6\u5f53\u524d\u7248\u672c<br \/>\n      CURRENT=$(kubectl get deployment babelbird-app -n ${K8S_NAMESPACE_PROD} -o jsonpath='{.spec.template.spec.containers[0].image}&#8217;)<br \/>\n      # \u56de\u6eda\u5230\u4e0a\u4e00\u4e2a\u7248\u672c<br \/>\n      kubectl rollout undo deployment\/babelbird-app -n ${K8S_NAMESPACE_PROD}<br \/>\n      kubectl rollout status deployment\/babelbird-app -n ${K8S_NAMESPACE_PROD} &#8211;timeout=600s<br \/>\n      # \u8bb0\u5f55\u56de\u6eda\u4e8b\u4ef6<br \/>\n      consul kv put babelbird\/deploy\/rollback &#8220;{\\&#8221;from\\&#8221;:\\&#8221;${CURRENT}\\&#8221;,\\&#8221;timestamp\\&#8221;:\\&#8221;$(date -u)\\&#8221;,\\&#8221;operator\\&#8221;:\\&#8221;${GITLAB_USER_NAME}\\&#8221;}&#8221;<br \/>\n  environment:<br \/>\n    name: production<br \/>\n    action: rollback<br \/>\n  when: manual<br \/>\n  only:<br \/>\n    &#8211; tags<br \/>\n    &#8211; \/^release\\\/.*$\/<br \/>\n  tags:<br \/>\n    &#8211; deploy<br \/>\n&#8220;`<\/p>\n<p>### 4.3 Helm Chart values\u914d\u7f6e<\/p>\n<p>&#8220;`yaml<br \/>\n# helm\/values-production.yaml<br \/>\n# \u5df4\u522b\u9e1f\u751f\u4ea7\u73af\u5883Helm\u914d\u7f6e<\/p>\n<p># \u955c\u50cf\u914d\u7f6e<br \/>\nimage:<br \/>\n  repository: registry.babelbird.com\/babelbird\/app<br \/>\n  pullPolicy: IfNotPresent<br \/>\n  # tag\u901a\u8fc7CI\/CD &#8211;set\u6ce8\u5165<br \/>\n  tag: &#8220;&#8221;<\/p>\n<p># \u526f\u672c\u6570\u914d\u7f6e<br \/>\nreplicaCount: 5<\/p>\n<p># \u5e94\u7528\u914d\u7f6e<br \/>\napp:<br \/>\n  name: babelbird<br \/>\n  env: production<br \/>\n  java_opts: &#8220;-Xms4g -Xmx8g -XX:+UseG1GC -XX:MaxGCPauseMillis=200 -Dfile.encoding=UTF-8&#8221;<br \/>\n  # \u4e1a\u52a1\u914d\u7f6e<br \/>\n  config:<br \/>\n    upload_max_size: &#8220;500M&#8221;<br \/>\n    preview_enabled: true<br \/>\n    watermarking_enabled: true<\/p>\n<p># K8s\u8d44\u6e90\u914d\u989d<br \/>\nresources:<br \/>\n  requests:<br \/>\n    cpu: &#8220;1000m&#8221;<br \/>\n    memory: &#8220;2Gi&#8221;<br \/>\n  limits:<br \/>\n    cpu: &#8220;4000m&#8221;<br \/>\n    memory: &#8220;8Gi&#8221;<\/p>\n<p># \u5065\u5eb7\u68c0\u67e5<br \/>\nlivenessProbe:<br \/>\n  httpGet:<br \/>\n    path: \/api\/health<br \/>\n    port: 8080<br \/>\n  initialDelaySeconds: 60<br \/>\n  periodSeconds: 10<br \/>\n  failureThreshold: 6<br \/>\n  successThreshold: 1<br \/>\n  timeoutSeconds: 5<\/p>\n<p>readinessProbe:<br \/>\n  httpGet:<br \/>\n    path: \/api\/ready<br \/>\n    port: 8080<br \/>\n  initialDelaySeconds: 30<br \/>\n  periodSeconds: 5<br \/>\n  failureThreshold: 3<br \/>\n  timeoutSeconds: 3<\/p>\n<p># \u63a2\u9488\uff08Startup Probe\uff0c\u7528\u4e8e\u6162\u542f\u52a8\u5e94\u7528\uff09<br \/>\nstartupProbe:<br \/>\n  httpGet:<br \/>\n    path: \/api\/health<br \/>\n    port: 8080<br \/>\n  initialDelaySeconds: 0<br \/>\n  periodSeconds: 10<br \/>\n  failureThreshold: 30  # \u6700\u591a\u7b49300\u79d2\u542f\u52a8\u5b8c\u6210<br \/>\n  timeoutSeconds: 5<\/p>\n<p># HorizontalPodAutoscaler<br \/>\nhpa:<br \/>\n  enabled: true<br \/>\n  minReplicas: 3<br \/>\n  maxReplicas: 20<br \/>\n  # \u57fa\u4e8eCPU\u548c\u81ea\u5b9a\u4e49\u6307\u6807\u6269\u7f29\u5bb9<br \/>\n  metrics:<br \/>\n    &#8211; type: Resource<br \/>\n      resource:<br \/>\n        name: cpu<br \/>\n        target:<br \/>\n          type: Utilization<br \/>\n          averageUtilization: 70<br \/>\n    &#8211; type: Pods<br \/>\n      pods:<br \/>\n        metric:<br \/>\n          name: babelbird_api_requests_per_second<br \/>\n        target:<br \/>\n          type: AverageValue<br \/>\n          averageValue: &#8220;50&#8221;<\/p>\n<p># \u6301\u4e45\u5316\u5b58\u50a8<br \/>\npersistence:<br \/>\n  enabled: true<br \/>\n  storageClass: &#8220;ssd-storage-class&#8221;<br \/>\n  size: &#8220;50Gi&#8221;<br \/>\n  accessMode: ReadWriteOnce<\/p>\n<p># Pod\u53cd\u4eb2\u548c\u6027\uff08\u6253\u6563\u5230\u4e0d\u540c\u8282\u70b9\uff09<br \/>\naffinity:<br \/>\n  podAntiAffinity:<br \/>\n    requiredDuringSchedulingIgnoredDuringExecution:<br \/>\n      &#8211; labelSelector:<br \/>\n          matchLabels:<br \/>\n            app: babelbird<br \/>\n        topologyKey: kubernetes.io\/hostname<\/p>\n<p># \u5bb9\u5fcd\u6c61\u70b9<br \/>\ntolerations:<br \/>\n  &#8211; key: &#8220;node-role.kubernetes.io\/control-plane&#8221;<br \/>\n    operator: &#8220;Exists&#8221;<br \/>\n    effect: &#8220;NoSchedule&#8221;<br \/>\n  &#8211; key: &#8220;node-role.kubernetes.io\/master&#8221;<br \/>\n    operator: &#8220;Exists&#8221;<br \/>\n    effect: &#8220;NoSchedule&#8221;<\/p>\n<p># \u5b89\u5168\u4e0a\u4e0b\u6587<br \/>\npodSecurityContext:<br \/>\n  runAsNonRoot: true<br \/>\n  runAsUser: 1000<br \/>\n  fsGroup: 1000<br \/>\n  seccompProfile:<br \/>\n    type: RuntimeDefault<\/p>\n<p>securityContext:<br \/>\n  readOnlyRootFilesystem: false<br \/>\n  allowPrivilegeEscalation: false<br \/>\n  capabilities:<br \/>\n    drop:<br \/>\n      &#8211; ALL<br \/>\n    add:<br \/>\n      &#8211; NET_BIND_SERVICE<\/p>\n<p># Ingress\u914d\u7f6e<br \/>\ningress:<br \/>\n  enabled: true<br \/>\n  className: nginx<br \/>\n  annotations:<br \/>\n    cert-manager.io\/cluster-issuer: letsencrypt-prod<br \/>\n    nginx.ingress.kubernetes.io\/proxy-body-size: &#8220;500m&#8221;<br \/>\n    nginx.ingress.kubernetes.io\/proxy-read-timeout: &#8220;300&#8221;<br \/>\n    nginx.ingress.kubernetes.io\/proxy-send-timeout: &#8220;300&#8221;<br \/>\n    nginx.ingress.kubernetes.io\/ssl-redirect: &#8220;true&#8221;<br \/>\n  hosts:<br \/>\n    &#8211; host: www.babelbird.com<br \/>\n      paths:<br \/>\n        &#8211; path: \/<br \/>\n          pathType: Prefix<br \/>\n  tls:<br \/>\n    &#8211; hosts:<br \/>\n        &#8211; www.babelbird.com<br \/>\n      secretName: babelbird-tls<\/p>\n<p># \u670d\u52a1\u76d1\u63a7\uff08PrometheusOperator\uff09<br \/>\nserviceMonitor:<br \/>\n  enabled: true<br \/>\n  interval: 15s<br \/>\n  scrapeTimeout: 10s<br \/>\n  namespace: monitoring<\/p>\n<p># PodDisruptionBudget\uff08\u786e\u4fdd\u6eda\u52a8\u66f4\u65b0\u65f6\u6700\u5c11\u53ef\u7528\u5b9e\u4f8b\u6570\uff09<br \/>\npodDisruptionBudget:<br \/>\n  enabled: true<br \/>\n  minAvailable: 2<\/p>\n<p># \u6eda\u52a8\u66f4\u65b0\u7b56\u7565<br \/>\nstrategy:<br \/>\n  type: RollingUpdate<br \/>\n  rollingUpdate:<br \/>\n    maxUnavailable: 0<br \/>\n    maxSurge: 1<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<p>## \u4e94\u3001\u8e29\u5751\u8bb0\u5f55\u4e0e\u7ecf\u9a8c\u603b\u7ed3<\/p>\n<p>### \u8e29\u57511\uff1aAnsible\u5e76\u53d1\u6267\u884c\u65f6SSH\u8fde\u63a5\u6570\u88ab\u6253\u6ee1<\/p>\n<p>**\u95ee\u9898\u63cf\u8ff0**\uff1a\u4e00\u6b21\u6027\u7ed920\u53f0\u673a\u5668\u8dd1Playbook\uff0c\u7ed3\u679c\u5927\u91cfSSH\u8fde\u63a5\u5931\u8d25\uff0c\u9519\u8bef\u4fe1\u606f\uff1a`Failed to connect to new shell &#8211; expected 12 received 0`\u3002<\/p>\n<p>**\u6839\u56e0**\uff1aSSH\u670d\u52a1\u5668\u7684MaxSessions\u9ed8\u8ba4\u503c\u662f10\uff0c\u5e76\u53d120\u4e2a\u8fde\u63a5\u65f6\u8d85\u51fa\u9650\u5236\u3002<\/p>\n<p>**\u89e3\u51b3\u65b9\u6848**\uff1a<br \/>\n&#8220;`ini<br \/>\n# ansible.cfg<br \/>\n[ssh_connection]<br \/>\npipelining = True<br \/>\ncontrol_path = \/tmp\/ansible-ssh-%%h-%%p-%%r<br \/>\nssh_args = -o ControlMaster=auto -o ControlPersist=60s<br \/>\n&#8220;`<br \/>\n\u540c\u65f6\u5728\u88ab\u7ba1\u7406\u673a\u5668\u7684`\/etc\/ssh\/sshd_config`\u4e2d\u589e\u52a0\uff1a<br \/>\n&#8220;`<br \/>\nMaxSessions 100<br \/>\n&#8220;`<\/p>\n<p>### \u8e29\u57512\uff1aAnsible Playbook\u6267\u884c\u8d85\u65f6\uff0c\u4efb\u52a1\u6302\u6b7b<\/p>\n<p>**\u95ee\u9898\u63cf\u8ff0**\uff1a\u67d0\u4e2atask\u6267\u884c\u65f6\u95f4\u8fc7\u957f\uff0cAnsible\u76f4\u63a5\u8d85\u65f6\u9000\u51fa\uff0c\u4f46\u5b9e\u9645\u547d\u4ee4\u5728\u540e\u53f0\u8fd8\u5728\u8fd0\u884c\u3002<\/p>\n<p>**\u89e3\u51b3\u65b9\u6848**\uff1a<br \/>\n&#8220;`yaml<br \/>\n# \u5728task\u7ea7\u522b\u8bbe\u7f6e\u8d85\u65f6<br \/>\n&#8211; name: \u957f\u65f6\u95f4\u8fd0\u884c\u7684\u547d\u4ee4<br \/>\n  shell: |<br \/>\n    # \u5b9e\u9645\u4efb\u52a1<br \/>\n  async: 3600       # \u4efb\u52a1\u6700\u957f\u8fd0\u884c\u65f6\u95f4\uff08\u79d2\uff09<br \/>\n  poll: 15          # \u6bcf15\u79d2\u68c0\u67e5\u4e00\u6b21\u72b6\u6001<br \/>\n  changed_when: false<\/p>\n<p># \u6216\u8005\u4f7f\u7528\u5f02\u6b65\u6279\u91cf\u6267\u884c\uff0c\u4e0d\u7b49\u5f85<br \/>\n&#8211; name: \u6279\u91cf\u91cd\u542f\u670d\u52a1<br \/>\n  shell: &#8220;systemctl restart {{ item }}&#8221;<br \/>\n  async: 1<br \/>\n  poll: 0  # \u4e0d\u7b49\u5f85\uff0c\u76f4\u63a5\u8fd4\u56de<br \/>\n  loop: &#8220;{{ groups[&#8216;all&#8217;] }}&#8221;<br \/>\n&#8220;`<\/p>\n<p>### \u8e29\u57513\uff1aHelm\u56de\u6eda\u65f6\u914d\u7f6e\u6587\u4ef6\u6ca1\u6709\u540c\u6b65\u56de\u6eda<\/p>\n<p>**\u95ee\u9898\u63cf\u8ff0**\uff1aHelm upgrade\u65f6\u65b0\u914d\u7f6e\u7684ConfigMap\u6709\u95ee\u9898\uff0c\u4f46\u56de\u6edaHelm\u7248\u672c\u540e\u53d1\u73b0ConfigMap\u8fd8\u662f\u65b0\u7248\u672c\u7684\u3002<\/p>\n<p>**\u6839\u56e0**\uff1aHelm\u7684release\u5386\u53f2\u53ea\u8bb0\u5f55\u4e86Chart\u4e2d\u7684templates\uff0c\u4e0d\u8bb0\u5f55`&#8211;set`\u53c2\u6570\u6ce8\u5165\u7684\u503c\u3002<\/p>\n<p>**\u89e3\u51b3\u65b9\u6848**\uff1a<br \/>\n&#8220;`yaml<br \/>\n# 1. \u6240\u6709\u914d\u7f6e\u53d8\u66f4\u90fd\u5fc5\u987b\u66f4\u65b0values-production.yaml\uff08Git\u7ba1\u7406\uff09<br \/>\n# 2. \u56de\u6eda\u65f6\u660e\u786e\u6307\u5b9avalues\u6587\u4ef6<br \/>\n&#8211; helm rollback babelbird 1 -n babelbird-app &#8211;reuse-values<\/p>\n<p># 3. \u5173\u952e\u914d\u7f6e\u901a\u8fc7ConfigMap\u7ba1\u7406\uff0c\u4e0d\u4f9d\u8d56helm set<br \/>\n# helm\/values-production.yaml<br \/>\nconfigMapRef:<br \/>\n  name: babelbird-config<br \/>\n  key: config.yaml<br \/>\n&#8220;`<\/p>\n<p>### \u8e29\u57514\uff1aDocker\u955c\u50cf\u62c9\u53d6\u8d85\u65f6\uff0c\u90e8\u7f72\u5931\u8d25<\/p>\n<p>**\u95ee\u9898\u63cf\u8ff0**\uff1aK8s Pod\u542f\u52a8\u65f6\u56e0\u4e3a\u955c\u50cf\u62c9\u53d6\u8d85\u65f6\uff08\u8d85\u65f6\u65f6\u95f4\u9ed8\u8ba43\u5206\u949f\uff09\uff0cPod\u4e00\u76f4\u5904\u4e8ePending\u72b6\u6001\u3002<\/p>\n<p>**\u89e3\u51b3\u65b9\u6848**\uff1a<br \/>\n&#8220;`yaml<br \/>\n# 1. \u5728Deployment\u4e2d\u914d\u7f6e\u955c\u50cf\u62c9\u53d6\u7b56\u7565\u548c\u8d85\u65f6<br \/>\nspec:<br \/>\n  containers:<br \/>\n    &#8211; name: babelbird<br \/>\n      image: registry.babelbird.com\/babelbird\/app:v2.3.0<br \/>\n      imagePullPolicy: IfNotPresent  # \u672c\u5730\u5df2\u6709\u5c31\u4e0d\u62c9\u53d6<br \/>\n  # 2. \u589e\u52a0\u62c9\u53d6\u8d85\u65f6\u65f6\u95f4<br \/>\n  imagePullSecrets:<br \/>\n    &#8211; name: registry-secret<\/p>\n<p># 3. \u914d\u7f6eKubelet\u7684imageGcThreshold<br \/>\n# \/var\/lib\/kubelet\/config.yaml<br \/>\nimageGCHighThresholdPercent: 85<br \/>\nimageGCLowThresholdPercent: 80<br \/>\nimageMinimumGCAge: 2m0s<br \/>\n&#8220;`<\/p>\n<p>### \u8e29\u57515\uff1a\u6eda\u52a8\u66f4\u65b0\u65f6\u670d\u52a1\u77ed\u6682\u4e0d\u53ef\u7528<\/p>\n<p>**\u95ee\u9898\u63cf\u8ff0**\uff1aK8s\u6eda\u52a8\u66f4\u65b0\u65f6\uff0c\u8001Pod\u88abTerminating\uff0c\u65b0Pod\u8fd8\u6ca1Ready\uff0c\u4e2d\u95f4\u6709\u51e0\u5341\u79d2\u670d\u52a1\u4e0d\u53ef\u7528\u3002<\/p>\n<p>**\u89e3\u51b3\u65b9\u6848**\uff1a<br \/>\n&#8220;`yaml<br \/>\n# 1. \u6eda\u52a8\u66f4\u65b0\u7b56\u7565\uff1amaxUnavailable=0\uff0c\u786e\u4fdd\u59cb\u7ec8\u6709Pod\u53ef\u7528<br \/>\nstrategy:<br \/>\n  type: RollingUpdate<br \/>\n  rollingUpdate:<br \/>\n    maxUnavailable: 0<br \/>\n    maxSurge: 1<\/p>\n<p># 2. \u914d\u7f6ePodDisruptionBudget<br \/>\npodDisruptionBudget:<br \/>\n  enabled: true<br \/>\n  minAvailable: 2<\/p>\n<p># 3. \u6dfb\u52a0readinessProbe\uff0c\u786e\u4fdd\u65b0Pod Ready\u540e\u624d\u5220\u9664\u8001Pod<br \/>\nreadinessProbe:<br \/>\n  httpGet:<br \/>\n    path: \/api\/ready<br \/>\n    port: 8080<br \/>\n  initialDelaySeconds: 30<br \/>\n  periodSeconds: 5<br \/>\n  failureThreshold: 3<\/p>\n<p># 4. \u914d\u7f6e\u4f18\u96c5\u7ec8\u6b62\uff08GracePeriodSeconds\uff09<br \/>\nterminationGracePeriodSeconds: 60  # \u7ed9\u8db3\u65f6\u95f4\u8ba9\u8fde\u63a5\u5173\u95ed<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<p>## \u516d\u3001\u6548\u679c\u91cf\u5316<\/p>\n<p>| \u6307\u6807 | \u624b\u5de5\u8fd0\u7ef4\u65f6\u4ee3 | Ansible+CI\/CD\u540e |<br \/>\n|&#8212;&#8212;|&#8212;&#8212;&#8212;&#8212;-|&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;|<br \/>\n| **\u5e94\u7528\u53d1\u5e03\u8017\u65f6** | 45\u5206\u949f\uff08\u542b\u624b\u5de5\u786e\u8ba4\uff09 | 8\u5206\u949f\uff08\u5168\u81ea\u52a8\uff09 |<br \/>\n| **\u914d\u7f6e\u4e00\u81f4\u6027\u9519\u8bef** | \u6bcf\u6708\u7ea63\u6b21 | 0\u6b21 |<br \/>\n| **\u56de\u6eda\u8017\u65f6** | 30\u5206\u949f\u4ee5\u4e0a | 3\u5206\u949f |<br \/>\n| **\u65b0\u673a\u5668\u521d\u59cb\u5316** | 3\u4eba\u65f6 | 5\u5206\u949f |<br \/>\n| **\u53d1\u5e03\u5931\u8d25\u7387** | 8% | <1% |\n| **\u7d27\u6025\u53d1\u5e03\u54cd\u5e94\u65f6\u95f4\uff08MTTR\uff09** | >30\u5206\u949f | 5\u5206\u949f |<br \/>\n| **\u8fd0\u7ef4\u4eba\u529b\u6210\u672c\uff08\u6708\u5747\uff09** | 160\u4eba\u65f6 | 40\u4eba\u65f6 |<\/p>\n<p>&#8212;<\/p>\n<p>## \u4e03\u3001\u5199\u5728\u6700\u540e<\/p>\n<p>\u81ea\u52a8\u5316\u8fd0\u7ef4\u4e0d\u662f\u4e00\u8e74\u800c\u5c31\u7684\uff0c\u5df4\u522b\u9e1f\u7684\u81ea\u52a8\u5316\u4f53\u7cfb\u4e5f\u662f\u82b1\u4e86\u5c06\u8fd1\u4e00\u5e74\u65f6\u95f4\u624d\u9010\u6b65\u5b8c\u5584\u7684\u3002\u51e0\u70b9\u5efa\u8bae\uff1a<\/p>\n<p>**1. \u4ece\u6700\u75db\u7684\u5730\u65b9\u5f00\u59cb**<br \/>\n\u4e0d\u8981\u4e00\u5f00\u59cb\u5c31\u60f3\u7740\u628a\u6240\u6709\u4e1c\u897f\u90fd\u81ea\u52a8\u5316\u3002\u5148\u628a\u6700\u9ad8\u9891\u3001\u6700\u5bb9\u6613\u51fa\u9519\u7684\u624b\u5de5\u64cd\u4f5c\u81ea\u52a8\u5316\uff0c\u6bd4\u5982\u53d1\u5e03\u548c\u56de\u6eda\u3002<\/p>\n<p>**2. \u5e42\u7b49\u662f\u7b2c\u4e00\u8981\u52a1**<br \/>\nAnsible\u7684\u6a21\u5757\u5929\u7136\u5e42\u7b49\uff0c\u4f46\u8981\u5c0f\u5fc3\u81ea\u5df1\u5199\u7684tasks\uff0c\u4e00\u884c`shell: rm -rf \/tmp\/*`\u5c31\u53ef\u80fd\u9020\u6210\u707e\u96be\u3002<\/p>\n<p>**3. \u7248\u672c\u63a7\u5236\u4e00\u5207**<br \/>\nAnsible\u7684Playbook\u3001Role\u3001Helm Chart\u3001CI\/CD\u914d\u7f6e\uff0c\u5168\u90e8\u8fdbGit\u3002\u6ca1\u6709\u7248\u672c\u7ba1\u7406\u7684\u81ea\u52a8\u5316\u4e0d\u662f\u771f\u6b63\u7684\u81ea\u52a8\u5316\u3002<\/p>\n<p>**4. \u81ea\u52a8\u5316\u4e5f\u8981\u6709\u7194\u65ad**<br \/>\n\u81ea\u52a8\u5316\u53d1\u5e03\u5931\u8d25\u65f6\u8981\u6709\u81ea\u52a8\u56de\u6eda\u673a\u5236\uff0c\u4e0d\u8981\u8ba9\u9519\u8bef\u914d\u7f6e\u5728\u7ebf\u4e0a\u5b58\u7559\u592a\u4e45\u3002<\/p>\n<p>**5. \u76d1\u63a7\u81ea\u52a8\u5316\u7684\u81ea\u52a8\u5316**<br \/>\nAnsible\u6267\u884c\u5931\u8d25\u3001CI\/CD pipeline\u5931\u8d25\uff0c\u90fd\u8981\u53d1\u544a\u8b66\u901a\u77e5\u3002\u76d1\u63a7\u76f2\u533a\u4e0d\u53ea\u662f\u4e1a\u52a1\u6307\u6807\uff0c\u8fd0\u7ef4\u5de5\u5177\u672c\u8eab\u7684\u6545\u969c\u540c\u6837\u8981\u76d1\u63a7\u3002<\/p>\n<p>> **\u53c2\u8003\u8d44\u6e90**<br \/>\n> &#8211; Ansible\u5b98\u65b9\u6587\u6863: https:\/\/docs.ansible.com\/<br \/>\n> &#8211; kube-prometheus-stack: https:\/\/github.com\/prometheus-community\/helm-charts<br \/>\n> &#8211; GitLab CI\/CD: https:\/\/docs.gitlab.com\/ee\/ci\/<br \/>\n> &#8211; Helm\u5b98\u65b9\u6587\u6863: https:\/\/helm.sh\/docs\/<br \/>\n> &#8211; \u5df4\u522b\u9e1f\u5b98\u7f51: https:\/\/www.babelbird.com<\/p>\n<p>&#8212;<\/p>\n<p>*\u672c\u6587\u6240\u6709\u4ee3\u7801\u548c\u914d\u7f6e\u5747\u6765\u81ea\u5df4\u522b\u9e1f\u751f\u4ea7\u73af\u5883\u5b9e\u9645\u8fd0\u884c\u7ecf\u9a8c\uff0c\u5df2\u9a8c\u8bc1\u53ef\u7528\u6027\u3002\u5982\u6709\u95ee\u9898\u6216\u5efa\u8bae\uff0c\u6b22\u8fce\u4ea4\u6d41\u3002*<\/p>\n","protected":false},"excerpt":{"rendered":"<p># \u4f01\u4e1a\u4e91\u76d8\u8fd0\u7ef4\u81ea\u52a8\u5316\uff1aAnsible\u811a\u672c\u4e0eCI\/CD\u6d41\u6c34\u7ebf&#8230; <a class=\"read-more\" href=\"https:\/\/www.babel.cc\/blog\/?p=6903\">[Continue Reading]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6903","post","type-post","status-publish","format-standard","hentry","category-1","no-post-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6903","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6903"}],"version-history":[{"count":1,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6903\/revisions"}],"predecessor-version":[{"id":6904,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6903\/revisions\/6904"}],"wp:attachment":[{"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.babel.cc\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}