├── .bluemix
├── deploy.json
├── icon.svg
├── pipeline.yml
├── toolchain.svg
└── toolchain.yml
├── .gitignore
├── .travis.yml
├── .yamllint.yml
├── CONTRIBUTING.md
├── LICENSE
├── MAINTAINERS.md
├── README-jp.md
├── README-ko.md
├── README-pt.md
├── README.md
├── docs
├── deploy-with-docker-on-linuxone.md
└── ubuntu.md
├── images
├── kube-wordpress-code.png
├── kube-wordpress.png
├── kube_kust.png
├── kube_ui.png
├── linuxone_testdrive.png
├── mysql.png
├── mysql_manage.png
├── wiki.png
├── wordpress.png
├── wordpress_comment.png
└── wpinstall-language.png
├── kustomization.yaml
├── local-volumes-compose.yaml
├── local-volumes.yaml
├── mysql-deployment.yaml
├── scripts
├── bx_auth.sh
├── install.sh
├── quickstart.sh
└── resources.sh
├── test-requirements.txt
├── tests
├── deploy-minikube.sh
└── test-kubernetes.sh
├── wordpress-deployment-compose.yaml
└── wordpress-deployment.yaml
/.bluemix/deploy.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json-schema.org/draft-04/schema#",
3 | "title": "Sample Deploy Stage",
4 | "description": "sample toolchain",
5 | "longDescription": "The Delivery Pipeline automates continuous deployment.",
6 | "type": "object",
7 | "properties": {
8 | "prod-region": {
9 | "description": "The bluemix region",
10 | "type": "string"
11 | },
12 | "prod-organization": {
13 | "description": "The bluemix org",
14 | "type": "string"
15 | },
16 | "prod-space": {
17 | "description": "The bluemix space",
18 | "type": "string"
19 | },
20 | "prod-app-name": {
21 | "description": "The name of your WordPress app",
22 | "type": "string"
23 | },
24 | "bluemix-user": {
25 | "description": "Your Bluemix user ID",
26 | "type": "string"
27 | },
28 | "bluemix-password": {
29 | "description": "Your Bluemix Password",
30 | "type": "string"
31 | },
32 | "bluemix-api-key": {
33 | "description": "Required for **Federated ID** since Federated ID can't login with Bluemix user and password via Bluemix CLI. You can obtain your API_KEY via https://console.ng.bluemix.net/iam/#/apikeys by clicking **Create API key** (Each API key only can be viewed once).",
34 | "type": "string"
35 | },
36 | "bluemix-cluster-account": {
37 | "description": "The GUID of the Bluemix account where you created the cluster. Retrieve it with [bx iam accounts].",
38 | "type": "string"
39 | },
40 | "bluemix-cluster-name": {
41 | "description": "Your cluster name. Retrieve it with [bx cs clusters].",
42 | "type": "string"
43 | }
44 | },
45 | "required": ["prod-region", "prod-organization", "prod-space", "bluemix-cluster-name"],
46 | "anyOf": [
47 | {
48 | "required": ["bluemix-user", "bluemix-password", "bluemix-cluster-account"]
49 | },
50 | {
51 | "required": ["bluemix-api-key"]
52 | }
53 | ],
54 | "form": [
55 | {
56 | "type": "validator",
57 | "url": "/devops/setup/bm-helper/helper.html"
58 | },
59 | {
60 | "type": "text",
61 | "readonly": false,
62 | "title": "Bluemix User ID",
63 | "key": "bluemix-user"
64 | },{
65 | "type": "password",
66 | "readonly": false,
67 | "title": "Bluemix Password",
68 | "key": "bluemix-password"
69 | },{
70 | "type": "password",
71 | "readonly": false,
72 | "title": "Bluemix API Key (Optional)",
73 | "key": "bluemix-api-key"
74 | },{
75 | "type": "password",
76 | "readonly": false,
77 | "title": "Bluemix Cluster Account ID",
78 | "key": "bluemix-cluster-account"
79 | },{
80 | "type": "text",
81 | "readonly": false,
82 | "title": "Bluemix Cluster Name",
83 | "key": "bluemix-cluster-name"
84 | },
85 | {
86 | "type": "table",
87 | "columnCount": 4,
88 | "widths": ["15%", "28%", "28%", "28%"],
89 | "items": [
90 | {
91 | "type": "label",
92 | "title": ""
93 | },
94 | {
95 | "type": "label",
96 | "title": "Region"
97 | },
98 | {
99 | "type": "label",
100 | "title": "Organization"
101 | },
102 | {
103 | "type": "label",
104 | "title": "Space"
105 | },
106 | {
107 | "type": "label",
108 | "title": "Production stage"
109 | },
110 | {
111 | "type": "select",
112 | "key": "prod-region"
113 | },
114 | {
115 | "type": "select",
116 | "key": "prod-organization"
117 | },
118 | {
119 | "type": "select",
120 | "key": "prod-space",
121 | "readonly": false
122 | }
123 | ]
124 | }
125 | ]
126 | }
127 |
--------------------------------------------------------------------------------
/.bluemix/icon.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.bluemix/pipeline.yml:
--------------------------------------------------------------------------------
1 | ---
2 | stages:
3 | - name: BUILD
4 | inputs:
5 | - type: git
6 | branch: master
7 | service: ${SAMPLE_REPO}
8 | triggers:
9 | - type: commit
10 | jobs:
11 | - name: Build
12 | type: builder
13 | artifact_dir: ''
14 | build_type: shell
15 | script: |-
16 | #!/bin/bash
17 | bash -n *.sh
18 | - name: DEPLOY
19 | inputs:
20 | - type: job
21 | stage: BUILD
22 | job: Build
23 | dir_name: null
24 | triggers:
25 | - type: stage
26 | properties:
27 | - name: BLUEMIX_USER
28 | type: text
29 | value: ${BLUEMIX_USER}
30 | - name: BLUEMIX_PASSWORD
31 | type: secure
32 | value: ${BLUEMIX_PASSWORD}
33 | - name: BLUEMIX_ACCOUNT
34 | type: secure
35 | value: ${BLUEMIX_ACCOUNT}
36 | - name: CLUSTER_NAME
37 | type: text
38 | value: ${CLUSTER_NAME}
39 | - name: API_KEY
40 | type: secure
41 | value: ${API_KEY}
42 | jobs:
43 | - name: Deploy
44 | type: deployer
45 | target:
46 | region_id: ${PROD_REGION_ID}
47 | organization: ${PROD_ORG_NAME}
48 | space: ${PROD_SPACE_NAME}
49 | application: Pipeline
50 | script: |
51 | #!/bin/bash
52 | . ./scripts/deploy-to-bluemix/install_bx.sh
53 | ./scripts/deploy-to-bluemix/bx_login.sh
54 | ./scripts/deploy-to-bluemix/deploy.sh
55 | hooks:
56 | - enabled: true
57 | label: null
58 | ssl_enabled: false
59 | url: >-
60 | https://devops-api-integration.stage1.ng.bluemix.net/v1/messaging/webhook/publish
61 |
--------------------------------------------------------------------------------
/.bluemix/toolchain.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.bluemix/toolchain.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: "Deploy Kubernetes WordPress sample to Bluemix"
3 | description: "Toolchain to deploy Kubernetes WordPress sample to Bluemix"
4 | version: 0.1
5 | image: data:image/svg+xml;base64,$file(toolchain.svg,base64)
6 | icon: data:image/svg+xml;base64,$file(icon.svg,base64)
7 | required:
8 | - deploy
9 | - sample-repo
10 |
11 | # Github repos
12 | sample-repo:
13 | service_id: githubpublic
14 | parameters:
15 | repo_name: "{{name}}"
16 | repo_url: https://github.com/IBM/scalable-wordpress-deployment-on-kubernetes
17 | type: clone
18 | has_issues: false
19 |
20 | # Pipelines
21 | sample-build:
22 | service_id: pipeline
23 | parameters:
24 | name: "{{name}}"
25 | ui-pipeline: true
26 | configuration:
27 | content: $file(pipeline.yml)
28 | env:
29 | SAMPLE_REPO: "sample-repo"
30 | CF_APP_NAME: "{{deploy.parameters.prod-app-name}}"
31 | PROD_SPACE_NAME: "{{deploy.parameters.prod-space}}"
32 | PROD_ORG_NAME: "{{deploy.parameters.prod-organization}}"
33 | PROD_REGION_ID: "{{deploy.parameters.prod-region}}"
34 | BLUEMIX_USER: "{{deploy.parameters.bluemix-user}}"
35 | BLUEMIX_PASSWORD: "{{deploy.parameters.bluemix-password}}"
36 | API_KEY: "{{deploy.parameters.bluemix-api-key}}"
37 | BLUEMIX_ACCOUNT: "{{deploy.parameters.bluemix-cluster-account}}"
38 | CLUSTER_NAME: "{{deploy.parameters.bluemix-cluster-name}}"
39 | execute: true
40 | services: ["sample-repo"]
41 | hidden: [form, description]
42 |
43 | # Deployment
44 | deploy:
45 | schema:
46 | $ref: deploy.json
47 | service-category: pipeline
48 | parameters:
49 | prod-app-name: "{{sample-repo.parameters.repo_name}}"
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore Vim files
2 | [._]*.s[a-w][a-z]
3 | [._]s[a-w][a-z]
4 | Session.vim
5 | .netrwhist
6 | *~
7 | tags
8 |
9 | # Ignore macOS files
10 | *.DS_Store
11 | .AppleDouble
12 | .LSOverride
13 | ._*
14 | .DocumentRevisions-V100
15 | .fseventsd
16 | .Spotlight-V100
17 | .TemporaryItems
18 | .Trashes
19 | .VolumeIcon.icns
20 | .com.apple.timemachine.donotpresent
21 | .AppleDB
22 | .AppleDesktop
23 | Network Trash Folder
24 | Temporary Items
25 | .apdisk
26 |
27 | # Ignore CI files
28 | dind-cluster-v1.7.sh*
29 | password.txt
30 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | ---
2 | language: python
3 | python: 2.7
4 | cache: pip
5 |
6 | notifications:
7 | slack:
8 | rooms:
9 | secure: "qb8F4QsJ6O6ygzZLDnp0ifmG6x8AX0Ne2KvuNOEjLwFeh45uYCMm4Ni1uiqryItyea3vZ7VOWdiR6hbBpVdXo0B3cOLDgQixQa8L89z9gQWocq7M0wo7RI9p3tGfBQ4xfNTPPLp9wzQ077h+8rXzSp6dbkWrUpUX3GEtcTz5B9rHasASGo4+azmvbdUa3CCv2MRVTEaftwBaf/F6CvMnxJdOFwd2tcFGs6sxQnWPbKEKWKqGyBqI347VcMYTmy9xmSQh8hMMxnzvYIyWFj2uTH6vYqBsMfAaI2nwBFKFVE9LzdKicoGdtzvC8hfEOC5gzORhBL3aQk4q7uhT39Cm7KcV+1/c391EuamyUAqtjPOCR3DS2CThaIEjYwi5xRMkWxqv9kZegb9vnd5BAjD6bYprZmuX6hkiaiKWPdiL3oxS8dyQG0h+rpBy1AUsDP4U7frK6QSaRHCtfx9eHncJvRxgX40D3YEGwPmHldGcSn/V6x2NyZFRAACxklzsn1vb//cjBr502w4nn1TeWLSnw3x9MdG3ZtZ8NjmeoXiN/nrQzd24l5PSysLPt/5W3t8GuQtaSzlVBXuYtNzBu9p0S2755KDXYA51SmZq8CV/T+0WPErLMLet/VJece4hThUgXdQHsIuayQzIGIozTFqe2/oOErOWYQ83MdC1vZ0PLxw="
10 | on_pull_requests: false
11 | on_sucess: change
12 |
13 | services:
14 | - docker
15 |
16 | before_install:
17 | - sudo apt-get install shellcheck
18 | - pip install -U -r test-requirements.txt
19 | - git clone https://github.com/IBM/pattern-ci
20 |
21 | before_script:
22 | - "./pattern-ci/tests/shellcheck-lint.sh"
23 | - "./pattern-ci/tests/yaml-lint.sh"
24 |
25 | jobs:
26 | include:
27 | - install: ./pattern-ci/scripts/install-minikube.sh
28 | script: ./tests/deploy-minikube.sh
29 |
--------------------------------------------------------------------------------
/.yamllint.yml:
--------------------------------------------------------------------------------
1 | ---
2 | rules:
3 | braces:
4 | min-spaces-inside: 0
5 | max-spaces-inside: 0
6 | min-spaces-inside-empty: 0
7 | max-spaces-inside-empty: 0
8 | brackets:
9 | min-spaces-inside: 0
10 | max-spaces-inside: 0
11 | min-spaces-inside-empty: 0
12 | max-spaces-inside-empty: 0
13 | colons:
14 | max-spaces-before: 0
15 | max-spaces-after: 1
16 | commas:
17 | max-spaces-before: 0
18 | min-spaces-after: 1
19 | max-spaces-after: 1
20 | comments:
21 | require-starting-space: true
22 | min-spaces-from-content: 2
23 | comments-indentation: enable
24 | document-end: disable
25 | document-start:
26 | present: true
27 | empty-lines:
28 | max: 2
29 | max-start: 0
30 | max-end: 0
31 | hyphens:
32 | max-spaces-after: 1
33 | indentation:
34 | spaces: consistent
35 | indent-sequences: true
36 | check-multi-line-strings: false
37 | key-duplicates: enable
38 | line-length:
39 | max: 80
40 | allow-non-breakable-words: true
41 | allow-non-breakable-inline-mappings: true
42 | level: warning
43 | new-line-at-end-of-file: enable
44 | new-lines:
45 | type: unix
46 | trailing-spaces: enable
47 | truthy: enable
48 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This is an open source project, and we appreciate your help!
4 |
5 | We use the GitHub issue tracker to discuss new features and non-trivial bugs.
6 |
7 | In addition to the issue tracker, [#journeys on
8 | Slack](https://dwopen.slack.com) is the best way to get into contact with the
9 | project's maintainers.
10 |
11 | To contribute code, documentation, or tests, please submit a pull request to
12 | the GitHub repository. Generally, we expect two maintainers to review your pull
13 | request before it is approved for merging. For more details, see the
14 | [MAINTAINERS](MAINTAINERS.md) page.
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/MAINTAINERS.md:
--------------------------------------------------------------------------------
1 | # Maintainers Guide
2 |
3 | This guide is intended for maintainers - anybody with commit access to one or
4 | more Code Pattern repositories.
5 |
6 | ## Methodology
7 |
8 | This repository does not have a traditional release management cycle, but
9 | should instead be maintained as a useful, working, and polished reference at
10 | all times. While all work can therefore be focused on the master branch, the
11 | quality of this branch should never be compromised.
12 |
13 | The remainder of this document details how to merge pull requests to the
14 | repositories.
15 |
16 | ## Merge approval
17 |
18 | The project maintainers use LGTM (Looks Good To Me) in comments on the pull
19 | request to indicate acceptance prior to merging. A change requires LGTMs from
20 | two project maintainers. If the code is written by a maintainer, the change
21 | only requires one additional LGTM.
22 |
23 | ## Reviewing Pull Requests
24 |
25 | We recommend reviewing pull requests directly within GitHub. This allows a
26 | public commentary on changes, providing transparency for all users. When
27 | providing feedback be civil, courteous, and kind. Disagreement is fine, so long
28 | as the discourse is carried out politely. If we see a record of uncivil or
29 | abusive comments, we will revoke your commit privileges and invite you to leave
30 | the project.
31 |
32 | During your review, consider the following points:
33 |
34 | ### Does the change have positive impact?
35 |
36 | Some proposed changes may not represent a positive impact to the project. Ask
37 | whether or not the change will make understanding the code easier, or if it
38 | could simply be a personal preference on the part of the author (see
39 | [bikeshedding](https://en.wiktionary.org/wiki/bikeshedding)).
40 |
41 | Pull requests that do not have a clear positive impact should be closed without
42 | merging.
43 |
44 | ### Do the changes make sense?
45 |
46 | If you do not understand what the changes are or what they accomplish, ask the
47 | author for clarification. Ask the author to add comments and/or clarify test
48 | case names to make the intentions clear.
49 |
50 | At times, such clarification will reveal that the author may not be using the
51 | code correctly, or is unaware of features that accommodate their needs. If you
52 | feel this is the case, work up a code sample that would address the pull
53 | request for them, and feel free to close the pull request once they confirm.
54 |
55 | ### Does the change introduce a new feature?
56 |
57 | For any given pull request, ask yourself "is this a new feature?" If so, does
58 | the pull request (or associated issue) contain narrative indicating the need
59 | for the feature? If not, ask them to provide that information.
60 |
61 | Are new unit tests in place that test all new behaviors introduced? If not, do
62 | not merge the feature until they are! Is documentation in place for the new
63 | feature? (See the documentation guidelines). If not do not merge the feature
64 | until it is! Is the feature necessary for general use cases? Try and keep the
65 | scope of any given component narrow. If a proposed feature does not fit that
66 | scope, recommend to the user that they maintain the feature on their own, and
67 | close the request. You may also recommend that they see if the feature gains
68 | traction among other users, and suggest they re-submit when they can show such
69 | support.
70 |
--------------------------------------------------------------------------------
/README-jp.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/IBM/Scalable-WordPress-deployment-on-Kubernetes)
2 |
3 | *他の言語で表示: [English](README.md) / [한국어](README-ko.md) / [português](README-po.md).*
4 |
5 | # スケーラブルな WordPress 実装を Kubernetes クラスター上にデプロイする
6 |
7 | このチュートリアルでは、Kubernetesクラスタの全機能を紹介し、世界で最も人気のあるWebサイトフレームワークを世界で最も人気のあるコンテナ・オーケストレーションプラットフォーム上に展開する方法を紹介します。KubernetesクラスタでWordPressをホストするための完全なロードマップを提供します。各コンポーネントは別々のコンテナまたはコンテナのグループで実行されます。
8 |
9 | Wordpressは典型的な多層アプリケーションを表し、各コンポーネントはそれぞれのコンテナを持ちます。WordPressコンテナはフロントエンド層となり、MySQLコンテナはWordPressのデータベース/バックエンド層になります。
10 |
11 | Kubernetesへのデプロイに加えて、フロントのWordPress層をどのように拡張できるか、そしてMySQLをIBM Cloudからのサービスとして仕様してWordPressフロントエンドで使用する方法も説明します。
12 |
13 | 
14 |
15 | ## Included Components
16 | - [WordPress (最新版)](https://hub.docker.com/_/wordpress/)
17 | - [MySQL (5.6)](https://hub.docker.com/_/mysql/)
18 | - [Kubernetes Clusters](https://cloud.ibm.com/docs/containers/cs_ov.html#cs_ov)
19 | - [IBM Cloud Compose for MySQL](https://cloud.ibm.com/catalog/services/compose-for-mysql)
20 | - [IBM Cloud DevOps Toolchain Service](https://cloud.ibm.com/catalog/services/continuous-delivery)
21 | - [IBM Cloud Kubernetes Service](https://cloud.ibm.com/catalog?taxonomyNavigation=apps&category=containers)
22 |
23 | ## 前提条件
24 |
25 | ローカルテスト用の[Minikube](https://kubernetes.io/docs/setup/minikube/)や、[IBM Cloud Kubernetes Service](https://github.com/IBM/container-journey-template)または[IBM Cloud Private](https://github.com/IBM/deploy-ibm-cloud-private/blob/master/README.md) のいずれかでKubernetes Clusterを作成します。このレポジトリのコードは[Kubernetes Cluster from IBM Cloud Container Service](https://cloud.ibm.com/docs/containers/cs_ov.html#cs_ov)上でTravis CIを使用して定期的にテストされています。
26 |
27 | ## 目的
28 |
29 | このシナリオでは、以下の作業について説明します:
30 |
31 | - 永続ディスクを定義するためローカル永続ボリュームを作成
32 | - 機密データを保護するためのシークレットを作成
33 | - WordPressフロントエンドのポットを1つ以上作成してデプロイ
34 | - MySQLデータベースを作成してデプロイします。(コンテナ内、またはバックエンドとしてIBM CloudのMySQLを使用)
35 |
36 | ## Deploy to IBM Cloud
37 | WordPressを直接IBM Cloudへデプロイしたい場合は、下の`Deploy to IBM Cloud`ボタンをクリックしてWordPressサンプルをデプロイするためのIBM Cloud DepOps サービスツールチェインとパイプラインを作成します。それ以外の場合は、[手順](##手順)へジャンプします
38 |
39 | [](https://cloud.ibm.com/devops/getting-started)
40 |
41 | ツールチェインとパイプラインを完成させるには、 [Toolchain instructions](https://github.com/IBM/container-journey-template/blob/master/Toolchain_Instructions_new.md) の指示に従ってください。
42 |
43 | ## 手順
44 | 1. [MySQL シークレットの設定](#1-mysql-シークレットの設定)
45 | 2. [ローカル永続ボリュームの作成](#2-ローカル永続ボリュームの作成)
46 | 3. [WordPressとMySQLのサービス/デプロイメントの作成と配布](#3-WordPressとMySQLのサービス/デプロイメントの作成と配布)
47 | - 3.1 [コンテナ内でMySQLを使用する](#31-コンテナ内でMySQLを使用する)
48 | - 3.2 [バックエンドとしてIBM Cloud MySQLを使用する](#32-バックエンドとしてIBM-Cloud-MySQLを使用する)
49 | 4. [外部のWordPressリンクにアクセスする](#4-外部のWordPressリンクにアクセスする)
50 | 5. [WordPressを使用する](#5-WordPressを使用する)
51 |
52 | # 1. MySQL シークレットの設定
53 |
54 | > *Quickstart option:* このレポジトリ内で `bash scripts/quickstart.sh`を実行します。
55 |
56 | 同じディレクトリに`password.txt`という名前の新しいファイルを作成し、希望のMySQLパスワードを`password.txt`の中に入れます。 (ASCII文字を含む任意の文字列).
57 |
58 |
59 | `password.txt`の末尾に改行が無いことを確認する必要があります。改行を削除するには、次のコマンドを使用します。
60 | ```bash
61 | tr -d '\n' .strippedpassword.txt && mv .strippedpassword.txt password.txt
62 | ```
63 |
64 | # 2. ローカル永続ボリュームの作成
65 | Kubernetesポッドのライフサイクルを超えてデータを保存するには、MySQLおよびWordPressアプリケーションが接続するための永続的なボリュームを作成する必要があります。
66 |
67 | #### IBM Cloud Kubernetes Service "ライト"クラスタ
68 | 次のコマンドを実行して、ローカル永続ボリュームを手動で作成します
69 | ```bash
70 | kubectl create -f local-volumes.yaml
71 | ```
72 | #### IBM Cloud Kubernetes Service "有料"クラスタ または Minikube
73 | MySQLおよびWordPressアプリケーションがデプロイされると、永続ボリュームが動的に作成されます。この手順は不要です
74 |
75 | # 3. WordPressとMySQLのサービス/デプロイメントの作成と配布
76 |
77 | ### 3.1 コンテナ内でMySQLを使用する
78 |
79 | > *Note:* IBM Cloud Compose-MySQLをバックエンドとして使用したい場合は、[バックエンドとしてIBM Cloud MySQLを使用する](#32-バックエンドとしてIBM-Cloud-MySQLを使用する)を参照してください
80 |
81 | 永続ボリュームをクラスタのローカルストレージにインストールします。その後、MySQLとWordPressのためのシークレットとサービスを作成します
82 | ```bash
83 | kubectl create secret generic mysql-pass --from-file=password.txt
84 | kubectl create -f mysql-deployment.yaml
85 | kubectl create -f wordpress-deployment.yaml
86 | ```
87 |
88 |
89 | すべてのポッドが実行されたら、次のコマンドを実行してポッド名を確認します。
90 | ```bash
91 | kubectl get pods
92 | ```
93 |
94 | これにより、Kubernetesクラスタからのポッドのリストが返されます
95 | ```bash
96 | NAME READY STATUS RESTARTS AGE
97 | wordpress-3772071710-58mmd 1/1 Running 0 17s
98 | wordpress-mysql-2569670970-bd07b 1/1 Running 0 1m
99 | ```
100 |
101 | それでは、[外部のWordPressリンクにアクセスする](#-4-外部のWordPressリンクにアクセスする)へ進んでください
102 |
103 | ### 3.2 バックエンドとしてIBM Cloud MySQLを使用する
104 |
105 | IBM CloudでCompose for MySQLをプロビジョニングします https://cloud.ibm.com/catalog/services/compose-for-mysql
106 |
107 | サービス認証情報に移動して、認証情報を確認してください。
108 | MySQLのホスト名、ポート番号、ユーザー、パスワードがあなたの認証情報URIの下にあり、以下のように見えるはずです
109 |
110 | 
111 |
112 | `wordpress-deployment.yaml`ファイルを編集し、WORDPRESS_DB_HOSTの値をMySQLのホスト名とポート番号に変更し(例: `value: :`)、 WORDPRESS_DB_USERの値をMySQLパスワードに変更します
113 |
114 | 環境変数は次のようになります
115 |
116 | ```yaml
117 | spec:
118 | containers:
119 | - image: wordpress:4.7.3-apache
120 | name: wordpress
121 | env:
122 | - name: WORDPRESS_DB_HOST
123 | value: sl-us-dal-9-portal.7.dblayer.com:22412
124 | - name: WORDPRESS_DB_USER
125 | value: admin
126 | - name: WORDPRESS_DB_PASSWORD
127 | value: XMRXTOXTDWOOPXEE
128 | ```
129 |
130 | `wordpress-deployment.yaml`を変更したら、次のコマンドを実行してWordPressをデプロイします
131 | ```bash
132 | kubectl create -f wordpress-deployment.yaml
133 | ```
134 |
135 | すべてのポッドが実行されたら、次のコマンドを実行してポッド名を確認します
136 | ```bash
137 | kubectl get pods
138 | ```
139 |
140 | これにより、Kubernetesクラスタからポッドのリストが返されます
141 |
142 | ```bash
143 | NAME READY STATUS RESTARTS AGE
144 | wordpress-3772071710-58mmd 1/1 Running 0 17s
145 | ```
146 |
147 | # 4. 外部のWordPressリンクにアクセスする
148 |
149 | > 有料クラスタがある場合は、NodePortの代わりにLoadBalancerを使用することができます。
150 | >
151 | >`kubectl edit services wordpress`
152 | >
153 | > `spec`の下で、 `type: NodePort` を `type: LoadBalancer` に変更してください
154 | >
155 | > **Note:** YAMLファイルを編集したあとに、`service "wordpress" edited`が表示されていることを確認してください。これはYAMLファイルが入力ミスや接続エラーなしで正常に編集されたことを意味します。
156 |
157 | クラスタのIPアドレスを取得するには
158 |
159 | ```bash
160 | $ bx cs workers
161 | OK
162 | ID Public IP Private IP Machine Type State Status
163 | kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 169.47.220.142 10.10.10.57 free normal Ready
164 | ```
165 |
166 | NodePort番号を取得するには、次のコマンドを実行する必要があります。
167 |
168 | ```bash
169 | $ kubectl get svc wordpress
170 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
171 | wordpress 10.10.10.57 80:30180/TCP 2m
172 | ```
173 |
174 | おめでとうございます。今あなたはあなたのWordPressサイトへアクセスするためのリンク**http://[IP]:[port number]** を使用することができるようになりました。
175 |
176 |
177 | > **Note:** 上記の例では、リンクは次のようになります http://169.47.220.142:30180
178 |
179 | Kubernetes UIでdeploymentのステータスを確認することができます。`kubectl proxy`を実行し、URL 'http://127.0.0.1:8001/ui' に移動して、WordPressコンテナの準備が整ったことを確認します。
180 |
181 | 
182 |
183 | > **Note:** ポッドが完全に機能するまで最大5分かかります。
184 |
185 |
186 |
187 | **(Optional)** クラスタ内にさらにリソースがあり、WordPress Webサイトをスケールアップしたい場合は、次のコマンドを実行して現在のdeploymentsを確認できます。
188 |
189 | ```bash
190 | $ kubectl get deployments
191 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
192 | wordpress 1 1 1 1 23h
193 | wordpress-mysql 1 1 1 1 23h
194 | ```
195 |
196 | これで、次のコマンドを実行してWordPressフロントエンドをスケールアップできます。
197 | ```bash
198 | $ kubectl scale deployments/wordpress --replicas=2
199 | deployment "wordpress" scaled
200 | $ kubectl get deployments
201 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
202 | wordpress 2 2 2 2 23h
203 | wordpress-mysql 1 1 1 1 23h
204 | ```
205 | ご覧のとおり、WordPressフロントエンドを実行している2つのポッドがあります。
206 |
207 | > **Note:** 無料クラスタユーザーの場合、無料利用枠のユーザーには限られたリソースしかないため、スケールアップは最大10個のポッドまでとすることをおすすめします。
208 |
209 | # 5. WordPressを使用する
210 |
211 | WordPressが起動しました。新しいユーザーとして登録して、WordPressをインストールすることができます。
212 | 
213 |
214 | WordPresをインストール後、新しいコメントを投稿することができます。
215 |
216 | 
217 |
218 |
219 | # トラブルシューティング
220 |
221 | 誤って改行付きのパスワードを作成した場合、MySQLサービスを認証することはできません。現在のシークレットを削除するには
222 |
223 | ```bash
224 | kubectl delete secret mysql-pass
225 | ```
226 |
227 | サービス、deployments、永続ボリューム要求を削除したい場合は、次のコマンドで実行できます
228 | ```bash
229 | kubectl delete deployment,service,pvc -l app=wordpress
230 | ```
231 |
232 | 永続ボリュームを削除したい場合は、次のコマンドで実行できます
233 | ```bash
234 | kubectl delete -f local-volumes.yaml
235 | ```
236 |
237 | WordPressの動作に時間がかかる場合、ログを調べることでWordPressのデバックすることができます。
238 | ```bash
239 | kubectl get pods # WordPressのポッド名を取得する
240 | kubectl logs [wordpress pod name]
241 | ```
242 |
243 |
244 | # References
245 | - このWordPressの例は、
246 | https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd にあるKubernetesのオープンソースの例[mysql-wordpress-pd](https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd)に基づいています。
247 |
248 |
249 | # ライセンス
250 | このコードパターンは、Apache Software License, Version 2の元でライセンスされています。このコードパターン内で呼び出される個別のサードパーティコードオブジェクトは、独自の個別ライセンスに従って、それぞれのプロバイダによってライセンスされます。コントリビュートの対象は[Developer Certificate of Origin, Version 1.1 (DCO)](https://developercertificate.org/) と [Apache Software License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt)です。
251 |
252 | [Apache Software License (ASL) FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)
253 |
--------------------------------------------------------------------------------
/README-ko.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/IBM/Scalable-WordPress-deployment-on-Kubernetes)
2 |
3 | *다른 언어로 보기: [English](README.md).*
4 |
5 | # 쿠버네티스 클러스터에 스케일링 가능한 워드프레스 구축하기
6 |
7 | 이 과정은 세계에서 가장 널리 이용되고 있는 컨테이너 오케스트레이션 플랫폼인 쿠버네티스의 여러 뛰어난 기능과 세계에서 가장 많이 이용되고 있는 웹사이트 프레임워크인 워드프레스를 쿠버네티스 상에 간단하게 배포하는 방법을 소개합니다. 단계별 가이드를 통해 IBM Bluemix 컨테이너 서비스의 쿠버네티스 클러스터에 워드프레스를 호스팅하는 방법 등을 안내합니다. 각 구성요소는 개별 컨테이너 또는 여러 컨테이너 그룹에서 실행됩니다.
8 |
9 | 워드프레스는 전형적인 멀티-티어(multi-tier) 앱으로, 각 구성요소마다 자체 컨테이너가 있습니다. 워드프레스 컨테이너는 프론트-엔드 티어가 되고, MySQL 컨테이너는 워드프레스의 데이터베이스/백엔드 티어가 됩니다.
10 |
11 | 쿠버네티스에서의 배포 외에도, 프론트 워드프레스 티어(front WordPress tier)를 스케일링하는 방법과 워드프레스 프론트 티어가 사용하는 MySQL을 Bluemix에서 DBaaS (Database as a Service)형태로 제공하는 Bluemix Compose for MySQL를 활용하여 사용하는 방법 또한 소개하겠습니다.
12 |
13 | 
14 |
15 | ## 포함된 구성요소
16 | - [워드프레스 (최신 버전)](https://hub.docker.com/_/wordpress/)
17 | - [MySQL (5.6)](https://hub.docker.com/_/mysql/)
18 | - [쿠버네티스 클러스터(Kubernetes Clusters)](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov)
19 | - [Bluemix 컨테이너 서비스(Bluemix Container Service)](https://console.ng.bluemix.net/catalog/?taxonomyNavigation=apps&category=containers)
20 | - [Bluemix Compose for MySQL](https://console.ng.bluemix.net/catalog/services/compose-for-mysql)
21 | - [Bluemix DevOps 툴체인 서비스](https://console.ng.bluemix.net/catalog/services/continuous-delivery)
22 |
23 | ## 전제조건
24 |
25 | 로컬 테스트 환경에서는 [미니큐브(Minikube)](https://kubernetes.io/docs/getting-started-guides/minikube)를, 클라우드 환경에서는 [IBM Bluemix 컨테이너 서비스(Bluemix Container Service)](https://github.com/IBM/container-journey-template)를 활용하여 쿠버네티스 클러스터를 생성하십시오. 여기 제공되는 코드는 [Bluemix 컨테이너 서비스의 쿠버네티스 클러스터(Kubernetes Cluster from Bluemix Container Service)](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov) 환경에서 Travis로 정기적인 테스트를 수행합니다.
26 |
27 | ## 목적
28 |
29 | 본 시나리오는 아래 작업의 진행을 위한 설명을 제공합니다.
30 |
31 | - 로컬 PersistentVolume(PV) 생성을 통한 영구적 디스크의 정의.
32 | - 비밀번호 생성을 통한 데이터의 보호.
33 | - 한 개 이상의 pod를 이용한 워드프레스 프론트엔드의 생성 및 배포.
34 | - MySQL 데이터베이스의 생성 및 배포(컨테이너 내에서의 생성 및 배포, 또는 Bluemix MySQL을 백엔드로 사용한 생성 및 배포).
35 |
36 | ## Bluemix에 배포하기
37 | 드프레스를 Bluemix에 직접 배포하려면, 아래의 ‘Deploy to Bluemix’ 버튼을 클릭하여 워드프레스 샘플 배포를 위한 Bluemix DevOps 서비스 툴체인과 파이프라인을 생성합니다. 그렇지 않은 경우, [단계](##단계) 로 이동합니다.
38 |
39 | [](https://console.ng.bluemix.net/devops/setup/deploy/)
40 |
41 | [툴체인 가이드를](https://github.com/IBM/container-journey-template/blob/master/Toolchain_Instructions_new.md) 참고하여 툴체인과 파이프라인을 생성하십시오.
42 | ## 단계
43 | 1. [MySQL 비밀키 설치](#1-mysql-비밀키-설치)
44 | 2. [워드프레스 및 MySQL의 서비스 및 배포 생성](#2-워드프레스-및-mysql의-서비스-및-배포-생성)
45 | - 2.1 [컨테이너에서 MySQL 사용하기](#21-컨테이너에서-mysql-사용하기)
46 | - 2.2 [Bluemix MySQL 사용하기](#22-bluemix-mysql-사용하기)
47 | 3. [외부 워드프레스 링크 이용하기](#3-외부-워드프레스-링크-이용하기)
48 | 4. [워드프레스 사용하기](#4-워드프레스-사용하기)
49 |
50 | # 1. MySQL 비밀키 설치
51 |
52 | > *빠른 시작을 위한 옵션:* Git 저장소 내의 `bash scripts/quickstart.sh`를 실행합니다.
53 |
54 | 동일한 디렉토리에 `password.txt` 라는 이름의 신규 파일을 생성하고, 원하는 MySQL 암호를 `password.txt`에 기록하십시오(ASCII 형식의 문자열 가능).
55 |
56 |
57 | `password.txt` 에 줄바꿈 문자가 있어서는 안됩니다. 다음 명령을 이용하면 줄바꿈 문자를 제거할 수 있습니다.
58 |
59 | ```bash
60 | tr -d '\n' .strippedpassword.txt && mv .strippedpassword.txt password.txt
61 | ```
62 |
63 | # 2. 워드프레스와 MySQL의 서비스 생성 및 배포하기
64 |
65 | ### 2.1 컨테이너에서 MySQL 사용하기
66 |
67 | > *참고:* Bluemix Compose-MySql을 백엔드로 이용하려는 경우, [Bluemix MySQL을 백엔드로 사용하기](#22-using-bluemix-mysql-as-backend)로 이동하십시오.
68 |
69 | 클러스터의 로컬 스토리지에 PersistentVolume(PV)를 설치하십시오. 그런 다음, MySQL 비밀 번호를 설정하고, MySQL 및 워드프레스의 서비스를 생성하십시오.
70 |
71 | ```bash
72 | kubectl create -f local-volumes.yaml
73 | kubectl create secret generic mysql-pass --from-file=password.txt
74 | kubectl create -f mysql-deployment.yaml
75 | kubectl create -f wordpress-deployment.yaml
76 | ```
77 |
78 |
79 | Pod가 모두 실행 중일 때, 다음 명령을 실행하여 pod 목록을 확인하십시오.
80 |
81 | ```bash
82 | kubectl get pods
83 | ```
84 |
85 | 다음 명령 이용 시, pod 목록이 쿠버네티스 클러스터로부터 반환됩니다.
86 |
87 | ```bash
88 | NAME READY STATUS RESTARTS AGE
89 | wordpress-3772071710-58mmd 1/1 Running 0 17s
90 | wordpress-mysql-2569670970-bd07b 1/1 Running 0 1m
91 | ```
92 |
93 | 이제, [외부 링크 (external link) 이용하기](#3-외부-워드프레스-링크-이용하기)로 이동하십시오.
94 |
95 | ### 2.2 Bluemix MySQL을 백엔드로 사용하기
96 |
97 | https://console.ng.bluemix.net/catalog/services/compose-for-mysql을 통해 Bluemix에 Compose for MySQL을 프로비저닝 하십시오.
98 |
99 | 서비스 신임정보로 이동하여 사용자 신임정보를 확인하십시오. 아래의 그림과 같이 사용자의 MySQL 호스트네임, 포트, 사용자, 암호 등이 사용자 신임정보 uri 밑에 있습니다.
100 |
101 | 
102 |
103 | `wordpress-deployment.yaml` 파일을 수정합니다. WORDPRESS_DB_HOST 값을 사용자의 MySQL 호스트네임과 포트(`value: :`)로, WORDPRESS_DB_USER 값을 여러분의 MySQL 사용자로, WORDPRESS_DB_PASSWORD 값을 사용자의 MySQL 암호로 변경하십시오.
104 |
105 | 환경 변수는 다음과 같습니다.
106 |
107 | ```yaml
108 | spec:
109 | containers:
110 | - image: wordpress:4.7.3-apache
111 | name: wordpress
112 | env:
113 | - name: WORDPRESS_DB_HOST
114 | value: sl-us-dal-9-portal.7.dblayer.com:22412
115 | - name: WORDPRESS_DB_USER
116 | value: admin
117 | - name: WORDPRESS_DB_PASSWORD
118 | value: XMRXTOXTDWOOPXEE
119 | ```
120 |
121 | `wordpress-deployment.yaml`수정 후에는 다음 명령들을 실행하여 워드프레스를 배포합니다.
122 |
123 | ```bash
124 | kubectl create -f local-volumes.yaml
125 | kubectl create -f wordpress-deployment.yaml
126 | ```
127 |
128 | 모든 pods가 실행 중일 때, 다음 명령을 실행하여 pod 이름들을 확인하십시오.
129 |
130 | ```bash
131 | kubectl get pods
132 | ```
133 |
134 | 명령 실행을 통해 pod 목록이 쿠버네티스 클러스터로부터 반환됩니다.
135 |
136 | ```bash
137 | NAME READY STATUS RESTARTS AGE
138 | wordpress-3772071710-58mmd 1/1 Running 0 17s
139 | ```
140 |
141 | # 3. 외부 워드프레스 링크 이용하기
142 |
143 | >(유료 계정만 해당됨!!) 유료 계정이 있는 경우, 다음 명령을 실행하여 로드밸런서(LoadBalancer)를 생성할 수 있습니다.
144 | >
145 | >`kubectl edit services wordpress`
146 | >
147 | > `spec`아래의 `type: NodePort` 를 `type: LoadBalancer`로 변경하십시오.
148 | >
149 | > **참고:** yaml 파일 수정 후에 `service "wordpress" edited` 가 나타나야 yaml 파일이 오타나 연결 오류 없이 성공적으로 수정되었다는 뜻입니다.
150 |
151 | 다음 명령을 실행하여 클러스터의 IP 주소를 확인할 수 있습니다.
152 |
153 | ```bash
154 | $ kubectl get nodes
155 | NAME STATUS AGE
156 | 169.47.220.142 Ready 23h
157 | ```
158 |
159 | 또한, 다음 명령을 실행하여 NodePort 번호를 확인해야 합니다.
160 |
161 | ```bash
162 | $ kubectl get svc wordpress
163 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
164 | wordpress 10.10.10.57 80:30180/TCP 2m
165 | ```
166 |
167 | 축하합니다. 지금부터는 **http://[IP]:[port number]** 링크를 이용하여 워드프레스 사이트에 접속할 수 있습니다.
168 |
169 |
170 | > **참고:** 위 예제의 링크는 http://169.47.220.142:30180 입니다.
171 |
172 | 쿠버네티스 UI에서 deployment를 확인할 수 있습니다. 'kubectl proxy' 를 실행하고 URL 'http://127.0.0.1:8001/ui' 로 이동하여 워드프레스 컨테이너가 언제 준비되는지 확인하십시오.
173 | 
174 |
175 | > **참고:** pod가 완전한 기능을 하기 전까지 최대 5분이 소요될 수 있습니다.
176 |
177 |
178 |
179 | **(선택사항)** 클러스터에 리소스가 추가적으로 있는 상황에서 워드프레스 웹사이트를 확장하려면, 다음 명령을 실행하여 현재 배포 현황을 확인할 수 있습니다.
180 | ```bash
181 | $ kubectl get deployments
182 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
183 | wordpress 1 1 1 1 23h
184 | wordpress-mysql 1 1 1 1 23h
185 | ```
186 |
187 | 이제, 다음 명령을 통해 워드프레스 프론트엔드의 스케일 아웃을 할 수 있습니다.
188 | ```bash
189 | $ kubectl scale deployments/wordpress --replicas=2
190 | deployment "wordpress" scaled
191 | $ kubectl get deployments
192 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
193 | wordpress 2 2 2 2 23h
194 | wordpress-mysql 1 1 1 1 23h
195 | ```
196 | 보이는 것과 같이 워드프레스 프론트엔드을 실행 중인 pods는 2개입니다.
197 |
198 | > **참고:** 무료 티어(free tier) 사용자에게는 리소스가 제한적이므로 최대 10개까지만 pods를 확장할 것을 권장합니다.
199 |
200 | # 4. 워드프레스 사용하기
201 |
202 | 워드프레스가 실행되었고, 이제 신규 사용자로 등록 및 워드프레스 설치를 진행할 수 있습니다.
203 |
204 | 
205 |
206 | 워드프레스가 설치되면 새로운 코멘트를 포스팅할 수 있습니다.
207 |
208 | 
209 |
210 |
211 | # 문제 해결
212 |
213 | 줄바꿈을 통해 실수로 암호를 생성하여 MySQL 서비스에 권한을 부여할 수 없는 경우, 다음 명령을 사용하여 현재 비밀키를 삭제할 수 있습니다.
214 |
215 | ```bash
216 | kubectl delete secret mysql-pass
217 | ```
218 |
219 | If you want to delete your services, deployments, and persistent volume claim, you can run
220 | ```bash
221 | kubectl delete deployment,service,pvc -l app=wordpress
222 | ```
223 |
224 | PersistentVolume (PV)를 삭제하려면, 다음 명령을 실행하십시오.
225 | ```bash
226 | kubectl delete -f local-volumes.yaml
227 | ```
228 |
229 | # 참조
230 | - • 이 워드프레스 예제는 [mysql-wordpress-pd](https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd) 웹사이트의 쿠버네티스의 https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd 오픈 소스 예제를 기반으로 작성되었습니다.
231 |
232 |
233 |
234 | # 라이센스
235 | [Apache 2.0](LICENSE)
236 |
--------------------------------------------------------------------------------
/README-pt.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/IBM/Scalable-WordPress-deployment-on-Kubernetes)
2 |
3 | *Ler em outros idiomas: [한국어](README-ko.md).*
4 |
5 | # Implementação escalável do WordPress no Cluster Kubernetes
6 |
7 | Esta jornada apresenta toda a força dos clusters Kubernetes e mostra como podemos implementar a estrutura de website mais popular do mundo na plataforma de orquestração de contêineres mais popular do mundo. Fornecemos um roteiro completo para hospedar o WordPress em um Cluster Kubernetes. Cada componente é executado em um contêiner ou grupo de contêineres separado.
8 |
9 | O WordPress representa um aplicativo típico multicamada; cada componente terá seus próprios contêineres. Os contêineres do WordPress serão a camada de front-end; o contêiner do MySQL será a camada de banco de dados/backend para o WordPress. A
10 |
11 | lém da implementação no Kubernetes, mostraremos como é possível ajustar a escala da camada frontal do WordPress e como o MySQL pode ser utilizado como um serviço do Bluemix para uso pelo front-end do WordPress.
12 |
13 | 
14 |
15 | ## Componentes inclusos
16 | - [WordPress (mais recente)](https://hub.docker.com/_/wordpress/)
17 | - [MySQL (5.6)](https://hub.docker.com/_/mysql/)
18 | - [Clusters Kubernetes](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov)
19 | - [Bluemix Container Service](https://console.ng.bluemix.net/catalog/?taxonomyNavigation=apps&category=containers)
20 | - [Bluemix Compose for MySQL](https://console.ng.bluemix.net/catalog/services/compose-for-mysql)
21 | - [Bluemix DevOps Toolchain Service](https://console.ng.bluemix.net/catalog/services/continuous-delivery)
22 |
23 | ## Pré-requisito
24 |
25 | Crie um cluster Kubernetes com [Minikube](https://kubernetes.io/docs/getting-started-guides/minikube) para testes locais ou com o [IBM Bluemix Container Service](https://github.com/IBM/container-journey-template) para implementação na cloud. O código é testado regularmente com relação ao [Cluster Kubernetes do Bluemix Container Service](https://console.ng.bluemix.net/docs/containers/cs_ov.html#cs_ov) usando Travis.
26 |
27 | ## Objetivos
28 |
29 | Este cenário fornece instruções para as tarefas a seguir: - Criar volumes persistentes locais para definir discos persistentes. - Criar um segredo para proteger dados sensíveis. - Criar e implementar o front-end do WordPress com um ou mais pods. - Criar e implementar o banco de dados do MySQL (em um contêiner ou usando o Bluemix MySQL como backend).
30 |
31 | ## Implementar no Bluemix
32 |
33 | Se quiser implementar o WordPress diretamente no Bluemix, clique no botão 'Deploy to Bluemix' abaixo para criar uma cadeia de ferramentas de serviço do Bluemix DevOps e um canal para implementação da amostra do WordPress ou avance para [Etapas](##steps)
34 |
35 | [](https://console.ng.bluemix.net/devops/setup/deploy/)
36 |
37 | Siga as [instruções da cadeia de ferramentas](https://github.com/IBM/container-journey-template/blob/master/Toolchain_Instructions_new.md) para concluir a cadeia de ferramentas e o canal.
38 |
39 | ## Etapas
40 | 1. [Configurar segredos do MySQL](#1-setup-mysql-secrets)
41 | 2. [Criar serviços e implementações para WordPress e MySQL](#2-create-services-and-deployments-for-wordpress-and-mysql)
42 | - 2.1 [Usando o MySQL no contêiner](#21-using-mysql-in-container)
43 | - 2.2 [Usando o Bluemix MySQL](#22-using-bluemix-mysql-as-backend)
44 | 3. [Acessando o link externo do WordPress](#3-accessing-the-external-wordpress-link)
45 | 4. [Usando o WordPress](#4-using-wordpress)
46 |
47 | # 1. Configurar segredos do MySQL
48 |
49 | > *Opção de iniciação rápida:* Neste repositório, execute `bash scripts/quickstart.sh`.
50 |
51 | Crie um novo arquivo chamado `password.txt` no mesmo diretório e coloque a senha desejada do MySQL em `password.txt` (pode ser qualquer cadeia de caractere com caracteres ASCII).
52 |
53 | Precisamos ter certeza de que `password.txt` não contém nenhuma linha nova posterior. Utilize o comando a seguir para remover possíveis linhas novas.
54 | ```bash
55 | tr -d '\n' .strippedpassword.txt && mv .strippedpassword.txt password.txt
56 | ```
57 |
58 | # 2. Criar serviços e implementações para WordPress e MySQL
59 |
60 | ### 2.1 Usando o MySQL no contêiner
61 | > *Observação:* se quiser usar o Bluemix Compose-MySql como backend, acesse [Usando o Bluemix MySQL como backend](#22-using-bluemix-mysql-as-backend).
62 |
63 | Instale o volume persistente no armazenamento local do cluster. Em seguida, crie o segredo e serviços para MySQL e WordPress.
64 |
65 | ```bash
66 | kubectl create -f local-volumes.yaml kubectl create secret generic mysql-pass --from-file=password.txt kubectl create -f mysql-deployment.yaml kubectl create -f wordpress-deployment.yaml
67 | ```
68 |
69 | Quando todos os pods estiverem em execução, execute os comandos a seguir para verificar os nomes deles.
70 |
71 | ```bash
72 | kubectl get pods
73 | ```
74 | Isso deve gerar uma lista de pods a partir do cluster Kubernetes.
75 | ```bash
76 | NAME READY STATUS RESTARTS AGE wordpress-3772071710-58mmd 1/1 Running 0 17s wordpress-mysql-2569670970-bd07b 1/1 Running 0 1m
77 | ```
78 | Agora, prossiga para [Acessando o link externo](#3-accessing-the-external-link).
79 |
80 | ### 2.2 Usando o Bluemix MySQL como backend
81 |
82 | Provision Compose for MySQL no Bluemix por meio de https://console.ng.bluemix.net/catalog/services/compose-for-mysql
83 |
84 |
85 | Acesse as credenciais de serviço e visualize suas credenciais. O nome do host, porta, usuário e senha do MySQL estão na URI da credencial e devem ter esta aparência:
86 |
87 | 
88 |
89 | Modifique o arquivo `wordpress-deployment.yaml`, altere o valor WORDPRESS_DB_HOST para o nome do host e a porta do MySQL (ou seja, `value: :`), o valor WORDPRESS_DB_USER para o usuário do MySQL e o valor WORDPRESS_DB_PASSWORD para a senha do MySQL.
90 |
91 | As variáveis de ambiente devem ter esta aparência:
92 |
93 | ```yaml
94 | spec: containers: - image: wordpress:4.7.3-apache name: wordpress env: - name: WORDPRESS_DB_HOST value: sl-us-dal-9-portal.7.dblayer.com:22412 - name: WORDPRESS_DB_USER value: admin - name: WORDPRESS_DB_PASSWORD value: XMRXTOXTDWOOPXEE
95 | ```
96 | Depois de modificar o `wordpress-deployment.yaml`, execute os comandos a seguir para implementar o WordPress.
97 |
98 | ```bash
99 | kubectl create -f local-volumes.yaml kubectl create -f wordpress-deployment.yaml ``` Quando todos os pods estiverem em execução, execute os comandos a seguir para verificar os nomes deles. ```bash kubectl get pods
100 | ```
101 | Isso deve gerar uma lista de pods a partir do cluster Kubernetes.
102 | ```bash
103 | NAME READY STATUS RESTARTS AGE wordpress-3772071710-58mmd 1/1 Running 0 17s
104 | ```
105 |
106 |
107 | # 3. Acessando o link externo do WordPress
108 |
109 | > Se tiver um cluster pago, será possível usar o LoadBalancer em vez do NodePort executando
110 | > >`kubectl edit services wordpress`
111 |
112 | > > Em `spec`, altere `type: NodePort` para `type: LoadBalancer`
113 |
114 | > > **Observação:** confira se `service "wordpress" edited` é exibido após a edição do arquivo yaml, porque isso significa que o arquivo yaml foi editado com sucesso, sem erros tipográficos ou de conexão.
115 |
116 | Para obter o endereço IP do cluster, utilize
117 | ```bash
118 | $ bx cs workers
119 | OK
120 | ID Public IP Private IP Machine Type State Status
121 | kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 169.47.220.142 10.10.10.57 free normal Ready
122 | ```
123 | Você também precisará executar o comando a seguir para obter o número NodePort.
124 | ```bash
125 | $ kubectl get svc wordpress NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE wordpress 10.10.10.57 80:30180/TCP 2m
126 | ```
127 | Parabéns. Agora, você pode usar o link **http://[IP]:[número da porta]** para acessar seu site no WordPress.
128 | > **Observação:** para o exemplo acima, o link seria http://169.47.220.142:30180 É possível verificar o status da implementação na interface com o usuário do Kubernetes.
129 |
130 | Execute `kubectl proxy` e acesse a URL 'http://127.0.0.1:8001/ui' para verificar quando o contêiner do WordPress ficará pronto.
131 |
132 | 
133 |
134 | >**Observação:** os pods podem levar até cinco minutos para começar a funcionar por completo.
135 |
136 | **(Opcional)** Se você tiver mais recursos no cluster e quiser aumentar a capacidade do website do WordPress, poderá executar os comandos a seguir para verificar as implementações atuais.
137 | ```bash
138 | $ kubectl get deployments
139 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
140 | wordpress 1 1 1 1 23h wordpress-mysql 1 1 1 1 23h
141 | ```
142 | Agora, é possível usar os comandos a seguir para aumentar a capacidade para o front-end do WordPress.
143 | ```bash
144 | $ kubectl scale deployments/wordpress --replicas=2 deployment "wordpress" scaled
145 | $ kubectl get deployments
146 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
147 | wordpress 2 2 2 2 23h wordpress-mysql 1 1 1 1 23h
148 | ```
149 | Como pode ser visto, temos dois pods que estão em execução no front-end do WordPress. > **Observação:** caso você seja um usuário de camada gratuita, recomendamos aumentar a capacidade para apenas 10 pods, uma vez que os usuários de camada gratuita têm recursos limitados.
150 |
151 | # 4. Usando o WordPress
152 | Com o WordPress em execução, é possível se inscrever como novo usuário e instalar o WordPress.
153 |
154 | 
155 |
156 | Depois de instalar o WordPress, você poderá publicar novos comentários.
157 |
158 | 
159 |
160 | # Resolução de problemas
161 | Caso tenha criado acidentalmente uma senha com linhas novas e não consiga autorizar o serviço do MySQL, você pode excluir o segredo atual usando
162 | ```bash
163 | kubectl delete secret mysql-pass
164 | ```
165 | Se quiser excluir seus serviços, implementações e a solicitação de volume persistente, você poderá executar
166 | ```bash
167 | kubectl delete deployment,service,pvc -l app=wordpress
168 | ```
169 | Para excluir seu volume persistente, é possível executar os comandos a seguir
170 | ```bash
171 | kubectl delete -f local-volumes.yaml
172 | ```
173 |
174 |
175 | # Referências
176 | - Este exemplo do WordPress baseia-se no exemplo de software livre do Kubernetes [mysql-wordpress-pd](https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd) em https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd.
177 | # Licença
178 | [Apache 2.0](LICENÇA)
179 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/IBM/Scalable-WordPress-deployment-on-Kubernetes)
2 |
3 | # Scalable WordPress deployment on Kubernetes Cluster
4 |
5 | This journey showcases the full power of Kubernetes clusters and shows how can we deploy the world's most popular website framework on top of world's most popular container orchestration platform. We provide a full roadmap for hosting WordPress on a Kubernetes Cluster. Each component runs in a separate container or group of containers.
6 |
7 | WordPress represents a typical multi-tier app and each component will have its own container(s). The WordPress containers will be the frontend tier and the MySQL container will be the database/backend tier for WordPress.
8 |
9 | In addition to deployment on Kubernetes, we will also show how you can scale the front WordPress tier, as well as how you can use MySQL as a service from IBM Cloud to be used by WordPress frontend.
10 |
11 | 
12 |
13 | ## Included Components
14 | - [WordPress (Latest)](https://hub.docker.com/_/wordpress/)
15 | - [MySQL (5.6)](https://hub.docker.com/_/mysql/)
16 | - [Kubernetes Clusters](https://cloud.ibm.com/docs/containers/cs_ov.html#cs_ov)
17 | - [IBM Cloud Compose for MySQL](https://cloud.ibm.com/catalog/services/compose-for-mysql)
18 |
19 | ## Prerequisite
20 |
21 | Create a Kubernetes cluster with either [Minikube](https://kubernetes.io/docs/setup/minikube/) for local testing, with [IBM Cloud Container Service](https://github.com/IBM/container-journey-template), or [IBM Cloud Private](https://github.com/IBM/deploy-ibm-cloud-private/blob/master/README.md) to deploy in cloud. The code here is regularly tested against [Kubernetes Cluster from IBM Cloud Container Service](https://cloud.ibm.com/docs/containers/cs_ov.html#cs_ov) using Travis.
22 |
23 | ## Objectives
24 |
25 | This scenario provides instructions for the following tasks:
26 |
27 | - Create local persistent volumes to define persistent disks.
28 | - Create a secret to protect sensitive data.
29 | - Create and deploy the WordPress frontend with one or more pods.
30 | - Create and deploy the MySQL database (either in a container or using IBM Cloud MySQL as backend).
31 |
32 | ## Deply to IBM Cloud
33 |
34 | If you want to deploy the WordPress directly to IBM Cloud, click on `Deploy to IBM Cloud` button below to create an IBM Cloud DevOps service toolchain and pipeline for deploying the WordPress sample, else jump to [steps](##Methods-to-Deploy)
35 |
36 | [](https://cloud.ibm.com/devops/setup/deploy?repository=https://github.com/IBM/Scalable-WordPress-deployment-on-Kubernetes&branch=master)
37 |
38 | # Methods to Deploy
39 |
40 | - [Using The Kustomization File](#Using-The-Kustomization-File)
41 | - [Manually deploying each file](#Manually-deploying-each-deployment)
42 | - [Using Compose for MySQL as Backend](#Using-IBM-Cloud-Compose-for-MySQL-as-backend)
43 |
44 | # Using The Kustomization File
45 |
46 | `kustomize` lets you customize raw, template-free YAML
47 | files for multiple purposes, leaving the original YAML
48 | untouched and usable as is.
49 |
50 | Create a new file called `password.txt` in the same directory and put your desired MySQL password inside `password.txt` (Could be any string with ASCII characters).
51 |
52 | How does our `kustomization.yaml` file looks like:
53 |
54 | ```yaml
55 | secretGenerator: #generates secrets within the cluster
56 | - name: mysql-pass
57 | files:
58 | - password.txt
59 | resources: #runs the .yaml files which are written below
60 | - local-volumes.yaml
61 | - mysql-deployment.yaml
62 | - wordpress-deployment.yaml
63 | ```
64 | #### To run the kustomization file
65 |
66 | ```bash
67 | kubectl apply -k ./
68 | ```
69 |
70 | #### Output
71 |
72 | ```bash
73 | secret/mysql-pass-c2f8979ct6 created
74 | service/wordpress-mysql created
75 | service/wordpress created
76 | deployment.apps/wordpress-mysql created
77 | deployment.apps/wordpress created
78 | persistentvolume/local-volume-1 created
79 | persistentvolume/local-volume-2 created
80 | persistentvolumeclaim/mysql-pv-claim created
81 | persistentvolumeclaim/wp-pv-claim created
82 | ```
83 | 
84 |
85 | [To read more about kustomization please click here](https://github.com/kubernetes-sigs/kustomize)
86 |
87 | Now please move on to [Accessing the External Link](#Accessing-the-external-wordpress-link).
88 |
89 | #### To remove the deployment
90 |
91 | ```bash
92 | kubectl delete -k ./
93 | ```
94 |
95 | # Manually deploying each deployment
96 | 1. [Setup MySQL Secrets](#1-setup-mysql-secrets)
97 | 2. [Create local persistent volumes](#2-create-local-persistent-volumes)
98 | 3. [Create Services and Deployments for WordPress and MySQL](#3-create-services-and-deployments-for-wordpress-and-mysql)
99 | 4. [Accessing the external WordPress link](#Accessing-the-external-wordpress-link)
100 | 5. [Using WordPress](#5-using-wordpress)
101 |
102 | ### 1. Setup MySQL Secrets
103 |
104 | Create a new file called `password.txt` in the same directory and put your desired MySQL password inside `password.txt` (Could be any string with ASCII characters).
105 |
106 |
107 | We need to make sure `password.txt` does not have any trailing newline. Use the following command to remove possible newlines.
108 |
109 | ```bash
110 | tr -d '\n' .strippedpassword.txt && mv .strippedpassword.txt password.txt
111 | ```
112 |
113 | ### 2. Create Local Persistent Volumes
114 | To save your data beyond the lifecycle of a Kubernetes pod, you will want to create persistent volumes for your MySQL and Wordpress applications to attach to.
115 |
116 | #### For "lite" IBM Cloud Kubernetes Service
117 | Create the local persistent volumes manually by running
118 | ```bash
119 | kubectl create -f local-volumes.yaml
120 | ```
121 | #### For paid IBM Cloud Kubernetes Service OR Minikube
122 | Persistent volumes are created dynamically for you when the MySQL and Wordpress applications are deployed. No action is needed.
123 |
124 | ### 3. Create Services and deployments for WordPress and MySQL
125 |
126 | > *Note:* If you want to use IBM Cloud Compose for MySql as your backend, please go to [Using IBM Cloud MySQL as backend](#Using-IBM-Cloud-MySQL-as-backend).
127 |
128 | Install persistent volume on your cluster's local storage. Then, create the secret and services for MySQL and WordPress.
129 |
130 | ```bash
131 | kubectl create secret generic mysql-pass --from-file=password.txt
132 | kubectl create -f mysql-deployment.yaml
133 | kubectl create -f wordpress-deployment.yaml
134 | ```
135 |
136 |
137 | When all your pods are running, run the following commands to check your pod names.
138 |
139 | ```bash
140 | kubectl get pods
141 | ```
142 |
143 | This should return a list of pods from the kubernetes cluster.
144 |
145 | ```bash
146 | NAME READY STATUS RESTARTS AGE
147 | wordpress-3772071710-58mmd 1/1 Running 0 17s
148 | wordpress-mysql-2569670970-bd07b 1/1 Running 0 1m
149 | ```
150 |
151 | Now please move on to [Accessing the External Link](#Accessing-the-external-wordpress-link).
152 |
153 | # Using IBM Cloud Compose for MySQL as backend
154 |
155 | ### Create Local Persistent Volumes
156 | To save your data beyond the lifecycle of a Kubernetes pod, you will want to create persistent volumes for your Wordpress applications to attach to.
157 |
158 | #### For "lite" IBM Cloud Kubernetes Service
159 | Create the local persistent volumes manually by running
160 | ```bash
161 | kubectl create -f local-volumes-compose.yaml
162 | ```
163 | #### For paid IBM Cloud Kubernetes Service OR Minikube
164 | Persistent volumes are created dynamically for you when the MySQL and Wordpress applications are deployed. No action is needed.
165 |
166 | Provision Compose for MySQL in IBM Cloud via https://cloud.ibm.com/catalog/services/compose-for-mysql
167 |
168 | Go to Service credentials and view your credentials (or add one if you don't see one created already). Your MySQL hostname, port, user, and password are under your credential url and it should look like this
169 |
170 | ```script
171 | db_type": "mysql",
172 | "uri_cli_1": "mysql -u <> -p<> --host sl-us-south-1-portal.47.dblayer.com --port 22817 --ssl-mode=REQUIRED",
173 | ```
174 |
175 | **Alternatively** you could also go to the manage tab and under "Connection Strings" you will be able to find the username, password, hostname as well as the port as shown below
176 |
177 | 
178 |
179 | Go to your `wordpress-deployment-compose.yaml` file, change WORDPRESS_DB_HOST's value to your MySQL hostname and port (i.e. `value: :`), WORDPRESS_DB_USER's value to your MySQL user, and WORDPRESS_DB_PASSWORD's value to your MySQL password.
180 |
181 | And the environment variables should look like this
182 |
183 | ```yaml
184 | spec:
185 | containers:
186 | - image: wordpress:latest
187 | name: wordpress-c
188 | env:
189 | - name: WORDPRESS_DB_HOST
190 | value: <>:<>
191 | - name: WORDPRESS_DB_USER
192 | value: <>
193 | - name: WORDPRESS_DB_PASSWORD
194 | value: <>
195 | ```
196 |
197 |
198 | After you modified the `wordpress-deployment-compose.yaml`, run the following commands to deploy WordPress.
199 |
200 | ```bash
201 | kubectl create -f wordpress-deployment-compose.yaml
202 | ```
203 |
204 | When all your pods are running, run the following commands to check your pod names.
205 |
206 | ```bash
207 | kubectl get pods
208 | ```
209 |
210 | This should return a list of pods from the kubernetes cluster.
211 |
212 | ```bash
213 | NAME READY STATUS RESTARTS AGE
214 | wordpress-3772071710-58mmd 1/1 Running 0 17s
215 | ```
216 | #### To access the service
217 |
218 | You can obtain your cluster's IP address using
219 |
220 | ```bash
221 | $ ibmcloud ks workers --cluster
222 | OK
223 | ID Public IP Private IP Machine Type State Status
224 | kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 169.47.220.142 10.10.10.57 free normal Ready
225 | ```
226 |
227 | You will also need to run the following command to get your NodePort number.
228 |
229 | ```bash
230 | $ kubectl get svc wordpress-c
231 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
232 | wordpress-c NodePort 172.21.179.176 80:30126/TCP 21s
233 | ```
234 |
235 | Congratulations. Now you can use the link **http://[IP of worker node]:[service port number]** to access your WordPress site.
236 |
237 |
238 | > **Note:** For the above example, the link would be http://169.47.220.142:30126
239 |
240 | ### To delete your deployment
241 |
242 | ````bash
243 | kubectl delete -f wordpress-deployment-compose.yaml
244 | kubectl delete -f local-volumes-compose.yaml
245 | ````
246 | # Accessing the external WordPress link
247 |
248 | > If you have a paid cluster, you can use LoadBalancer instead of NodePort by running
249 | >
250 | >`kubectl edit services wordpress`
251 | >
252 | > Under `spec`, change `type: NodePort` to `type: LoadBalancer`
253 | >
254 | > **Note:** Make sure you have `service "wordpress" edited` shown after editing the yaml file because that means the yaml file is successfully edited without any typo or connection errors.
255 |
256 | You can obtain your cluster's IP address using
257 |
258 | ```bash
259 | $ ibmcloud ks workers --cluster
260 | OK
261 | ID Public IP Private IP Machine Type State Status
262 | kube-hou02-pa817264f1244245d38c4de72fffd527ca-w1 169.47.220.142 10.10.10.57 free normal Ready
263 | ```
264 |
265 | You will also need to run the following command to get your NodePort number.
266 |
267 | ```bash
268 | $ kubectl get svc wordpress
269 | NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
270 | wordpress 10.10.10.57 80:30180/TCP 2m
271 | ```
272 |
273 | Congratulations. Now you can use the link **http://[IP of worker node]:[service port number]** to access your WordPress site.
274 |
275 |
276 | > **Note:** For the above example, the link would be http://169.47.220.142:30180
277 |
278 | You can check the status of your deployment on Kubernetes UI. Run `kubectl proxy` and go to URL 'http://127.0.0.1:8001/ui' to check when the WordPress container becomes ready.
279 |
280 | 
281 |
282 | > **Note:** It can take up to 5 minutes for the pods to be fully functioning.
283 |
284 |
285 |
286 | **(Optional)** If you have more resources in your cluster, and you want to scale up your WordPress website, you can run the following commands to check your current deployments.
287 | ```bash
288 | $ kubectl get deployments
289 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
290 | wordpress 1 1 1 1 23h
291 | wordpress-mysql 1 1 1 1 23h
292 | ```
293 | # To Scale Your Application
294 |
295 | Now, you can run the following commands to scale up for WordPress frontend.
296 | ```bash
297 | $ kubectl scale deployments/wordpress --replicas=2
298 | deployment "wordpress" scaled
299 | ```
300 |
301 | #### Check your added replica
302 | ```bash
303 | $ kubectl get deployments
304 | NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
305 | wordpress 2 2 2 2 23h
306 | wordpress-mysql 1 1 1 1 23h
307 | ```
308 | As you can see, we now have 2 pods that are running the WordPress frontend.
309 |
310 | > **Note:** If you are a free tier user, we recommend you only scale up to 10 pods since free tier users have limited resources.
311 |
312 | # 5. Using WordPress
313 |
314 | Now that WordPress is running you can register as a new user and install WordPress.
315 |
316 | 
317 |
318 | After installing WordPress, you can post new comments.
319 |
320 | 
321 |
322 |
323 | # Troubleshooting
324 |
325 | If you accidentally created a password with newlines and you can not authorize your MySQL service, you can delete your current secret using
326 |
327 | ```bash
328 | kubectl delete secret mysql-pass
329 | ```
330 |
331 | If you want to delete your services, deployments, and persistent volume claim, you can run
332 | ```bash
333 | kubectl delete deployment,service,pvc -l app=wordpress
334 | ```
335 |
336 | If you want to delete your persistent volume, you can run the following commands
337 | ```bash
338 | kubectl delete -f local-volumes.yaml
339 | ```
340 |
341 | If WordPress is taking a long time, you can debug it by inspecting the logs
342 | ```bash
343 | kubectl get pods # Get the name of the wordpress pod
344 | kubectl logs [wordpress pod name]
345 | ```
346 |
347 |
348 | # References
349 | - This WordPress example is based on Kubernetes's open source example [mysql-wordpress-pd](https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd) at https://github.com/kubernetes/kubernetes/tree/master/examples/mysql-wordpress-pd.
350 |
351 |
352 | ## License
353 | This code pattern is licensed under the Apache Software License, Version 2. Separate third-party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the [Developer Certificate of Origin, Version 1.1](https://developercertificate.org/) and the [Apache License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt).
354 |
355 | [Apache License FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)
356 |
--------------------------------------------------------------------------------
/docs/deploy-with-docker-on-linuxone.md:
--------------------------------------------------------------------------------
1 | # Deploy with Docker on LinuxONE
2 |
3 | Open source software has expanded from a low-cost alternative to a platform for enterprise databases, clouds and next-generation apps. These workloads need higher levels of scalability, security and availability from the underlying hardware infrastructure.
4 |
5 | LinuxONE was built for open source so you can harness the agility of the open revolution on the industry’s most secure, scalable and high-performing Linux server. In this journey we will show how to run open source Cloud-Native workloads on LinuxONE
6 |
7 | ## Included Components
8 |
9 | - [LinuxONE](https://www-03.ibm.com/systems/linuxone/open-source/index.html)
10 | - [Docker](https://www.docker.com)
11 | - [Docker Store](https://sore.docker.com)
12 | - [WordPress](https://workpress.com)
13 | - [MariaDB](https://mariadb.org)
14 |
15 | ## Prerequisites
16 |
17 | Register at [LinuxONE Community Cloud](https://developer.ibm.com/linuxone/) for a trial account.
18 | We will be using a Ret Hat base image for this journey, so be sure to chose the
19 | red 'Request your trial' button on the lower left side of this page:
20 | 
21 |
22 | ## Steps
23 |
24 | [Docker Hub](https://hub.docker.com) makes it rather simple to get started with
25 | containers, as there are quite a few images ready to for your to use. You can
26 | browse the list of images that are compatable with LinuxONE by doing a search
27 | on the ['s390x'](https://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=s390x&starCount=0) tag.
28 | We will start off with everyone's favorite demo: an installation of WordPress.
29 | These instructions assume a base RHEL 7.2 image. If you are using Ubuntu,
30 | please follow the separate [instructions](docs/ubuntu.md)
31 |
32 | ### 1. Install docker
33 | ```text
34 | :~$ yum install docker.io
35 | ```
36 |
37 | ### 2. Install docker-compose
38 |
39 | Install dependencies
40 |
41 | ```text
42 | sudo yum install -y python-setuptools
43 | ```
44 |
45 | Install pip with easy_install
46 |
47 | ```text
48 | sudo easy_install pip
49 | ```
50 |
51 | Upgrade backports.ssl_match_hostname
52 |
53 | ```text
54 | sudo pip install backports.ssl_match_hostname --upgrade
55 | ```
56 |
57 | Finally, install docker-compose itself
58 | ```text
59 | sudo pip install docker-compose
60 | ```
61 |
62 | ### 3. Run and install WordPress
63 |
64 | Now that we have docker-compose installed, we will create a docker-compose.yml
65 | file. This will specify a couple of containers from the Docker Store that
66 | have been specifically written for z systems.
67 |
68 | ```text
69 | vim docker-compose.yml
70 | ```
71 |
72 | ```text
73 | version: '2'
74 |
75 | services:
76 |
77 | wordpress:
78 | image: s390x/wordpress
79 | ports:
80 | - 8080:80
81 | environment:
82 | WORDPRESS_DB_PASSWORD: example
83 |
84 | mysql:
85 | image: brunswickheads/mariadb-5.5-s390x
86 | environment:
87 | MYSQL_ROOT_PASSWORD: example
88 | ```
89 |
90 | And finally, run docker-compose (from the same directory you created the .yml)
91 |
92 | ```text
93 | sudo docker-compose up -d
94 | ```
95 |
96 | After all is installed, you can check the status of your containers
97 | ```text
98 | :~$ sudo docker-compose ps
99 | Name Command State Ports
100 | ----------------------------------------------------------------------------------
101 | linux1_mysql_1 /docker-entrypoint.sh mysq ... Up 3306/tcp
102 | linux1_wordpress_1 /entrypoint.sh apache2-for ... Up 0.0.0.0:8080->80/tcp
103 | ```
104 | and checkout your new blog by using a webbrowser to access 'http://[Your LinuxONE IP Address]:8080'
105 |
106 | 
107 |
108 | You will see the default setup screen requesting your language. The following
109 | screen will ask you to specify a default username/password for the WordPress
110 | installation, after which you will be up and running!
111 |
--------------------------------------------------------------------------------
/docs/ubuntu.md:
--------------------------------------------------------------------------------
1 | ### 1. Install docker
2 | ```text
3 | :~$ apt install docker.io
4 | ```
5 |
6 | ### 2. Install docker-compose
7 |
8 | Install dependencies
9 |
10 | ```text
11 | sudo apt-get update
12 | sudo apt-get install -y python-pip
13 | pip install --upgrade
14 | ```
15 |
16 | Then docker-compose itself
17 | ```text
18 | sudo pip install docker-compose
19 | ```
20 |
--------------------------------------------------------------------------------
/images/kube-wordpress-code.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/kube-wordpress-code.png
--------------------------------------------------------------------------------
/images/kube-wordpress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/kube-wordpress.png
--------------------------------------------------------------------------------
/images/kube_kust.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/kube_kust.png
--------------------------------------------------------------------------------
/images/kube_ui.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/kube_ui.png
--------------------------------------------------------------------------------
/images/linuxone_testdrive.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/linuxone_testdrive.png
--------------------------------------------------------------------------------
/images/mysql.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/mysql.png
--------------------------------------------------------------------------------
/images/mysql_manage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/mysql_manage.png
--------------------------------------------------------------------------------
/images/wiki.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/wiki.png
--------------------------------------------------------------------------------
/images/wordpress.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/wordpress.png
--------------------------------------------------------------------------------
/images/wordpress_comment.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/wordpress_comment.png
--------------------------------------------------------------------------------
/images/wpinstall-language.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IBM/Scalable-WordPress-deployment-on-Kubernetes/6ef71f6db686767f39217e1372c3f721a8b586ef/images/wpinstall-language.png
--------------------------------------------------------------------------------
/kustomization.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | secretGenerator:
3 | - name: mysql-pass
4 | files:
5 | - password.txt
6 | resources:
7 | - local-volumes.yaml
8 | - mysql-deployment.yaml
9 | - wordpress-deployment.yaml
10 |
--------------------------------------------------------------------------------
/local-volumes-compose.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: PersistentVolume
4 | metadata:
5 | name: local-volume-3
6 | labels:
7 | type: local
8 | spec:
9 | capacity:
10 | storage: 20Gi
11 | accessModes:
12 | - ReadWriteOnce
13 | hostPath:
14 | path: /tmp/data/lv-3
15 | persistentVolumeReclaimPolicy: Recycle
16 |
--------------------------------------------------------------------------------
/local-volumes.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: PersistentVolume
4 | metadata:
5 | name: local-volume-1
6 | labels:
7 | type: local
8 | spec:
9 | capacity:
10 | storage: 20Gi
11 | accessModes:
12 | - ReadWriteOnce
13 | hostPath:
14 | path: /tmp/data/lv-1
15 | persistentVolumeReclaimPolicy: Recycle
16 | ---
17 | apiVersion: v1
18 | kind: PersistentVolume
19 | metadata:
20 | name: local-volume-2
21 | labels:
22 | type: local
23 | spec:
24 | capacity:
25 | storage: 20Gi
26 | accessModes:
27 | - ReadWriteOnce
28 | hostPath:
29 | path: /tmp/data/lv-2
30 | persistentVolumeReclaimPolicy: Recycle
31 |
--------------------------------------------------------------------------------
/mysql-deployment.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Service
3 | metadata:
4 | name: wordpress-mysql
5 | labels:
6 | app: wordpress-mysql
7 | spec:
8 | ports:
9 | - port: 3306
10 | selector:
11 | app: wordpress-mysql
12 | ---
13 | apiVersion: apps/v1
14 | kind: Deployment
15 | metadata:
16 | name: wordpress-mysql
17 | labels:
18 | app: wordpress-mysql
19 | spec:
20 | selector:
21 | matchLabels:
22 | app: wordpress-mysql
23 | strategy:
24 | type: Recreate
25 | template:
26 | metadata:
27 | labels:
28 | app: wordpress-mysql
29 | spec:
30 | containers:
31 | - image: mysql:5.6
32 | name: mysql
33 | env:
34 | - name: MYSQL_DATABASE
35 | value: wordpress
36 | - name: MYSQL_ROOT_PASSWORD
37 | valueFrom:
38 | secretKeyRef:
39 | name: mysql-pass
40 | key: password
41 | ports:
42 | - containerPort: 3306
43 | name: mysql
44 | volumeMounts:
45 | - name: mysql-persistent-storage
46 | mountPath: /var/lib/mysql
47 | volumes:
48 | - name: mysql-persistent-storage
49 | persistentVolumeClaim:
50 | claimName: mysql-pv-claim
51 | ---
52 | apiVersion: v1
53 | kind: PersistentVolume
54 | metadata:
55 | name: mysql-pv-volume
56 | labels:
57 | type: local
58 | spec:
59 | storageClassName: manual
60 | capacity:
61 | storage: 20Gi
62 | accessModes:
63 | - ReadWriteOnce
64 | hostPath:
65 | path: "/tmp/mysql/data"
66 | persistentVolumeReclaimPolicy: Recycle
67 | ---
68 | apiVersion: v1
69 | kind: PersistentVolumeClaim
70 | metadata:
71 | name: mysql-pv-claim
72 | spec:
73 | storageClassName: manual
74 | accessModes:
75 | - ReadWriteOnce
76 | resources:
77 | requests:
78 | storage: 20Gi
79 |
--------------------------------------------------------------------------------
/scripts/bx_auth.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | # This script is intended to be run by Travis CI. If running elsewhere, invoke
4 | # it with: TRAVIS_PULL_REQUEST=false [path to script]
5 | # If no credentials are provided at runtime, bx will use the environment
6 | # variable BLUEMIX_API_KEY. If no API key is set, it will prompt for
7 | # credentials.
8 |
9 | # shellcheck disable=SC1090
10 | source "$(dirname "$0")"/../scripts/resources.sh
11 |
12 | BLUEMIX_ORG="Developer Advocacy"
13 | BLUEMIX_SPACE="dev"
14 |
15 | is_pull_request "$0"
16 |
17 | echo "Authenticating to Bluemix"
18 | bx login -a https://api.ng.bluemix.net
19 |
20 | echo "Targeting Bluemix org and space"
21 | bx target -o "$BLUEMIX_ORG" -s "$BLUEMIX_SPACE"
22 |
23 | echo "Initializing Bluemix Container Service"
24 | bx cs init
25 |
--------------------------------------------------------------------------------
/scripts/install.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | # This script is intended to be run by Travis CI. If running elsewhere, invoke
4 | # it with: TRAVIS_PULL_REQUEST=false [path to script]
5 |
6 | # shellcheck disable=SC1090
7 | source "$(dirname "$0")"/../scripts/resources.sh
8 |
9 | is_pull_request "$0"
10 |
11 | echo "Install Bluemix CLI"
12 | curl -L https://public.dhe.ibm.com/cloud/bluemix/cli/bluemix-cli/latest/IBM_Cloud_CLI_amd64.tar.gz > Bluemix_CLI.tar.gz
13 | tar -xvf Bluemix_CLI.tar.gz
14 | sudo ./Bluemix_CLI/install_bluemix_cli
15 |
16 | echo "Install kubectl"
17 | curl -LO https://storage.googleapis.com/kubernetes-release/release/"$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)"/bin/linux/amd64/kubectl
18 | chmod 0755 kubectl
19 | sudo mv kubectl /usr/local/bin
20 |
21 | echo "Configuring bx to disable version check"
22 | bx config --check-version=false
23 | echo "Checking bx version"
24 | bx --version
25 | echo "Install the Bluemix container-service plugin"
26 | bx plugin install container-service -r Bluemix
27 |
28 | if [[ -n "$DEBUG" ]]; then
29 | bx --version
30 | bx plugin list
31 | fi
32 |
--------------------------------------------------------------------------------
/scripts/quickstart.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo 'password' > password.txt
3 | tr -d '\n' .strippedpassword.txt && mv .strippedpassword.txt password.txt
4 | kubectl apply -k ./
--------------------------------------------------------------------------------
/scripts/resources.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # This script contains functions used by many of the scripts found in scripts/
4 | # and tests/.
5 |
6 | test_failed(){
7 | echo -e >&2 "\033[0;31m$1 test failed!\033[0m"
8 | exit 1
9 | }
10 |
11 | test_passed(){
12 | echo -e "\033[0;32m$1 test passed!\033[0m"
13 | }
14 |
15 | is_pull_request(){
16 | if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then
17 | echo -e "\033[0;33mPull Request detected; not running $1!\033[0m"
18 | exit 0
19 | fi
20 | }
21 |
--------------------------------------------------------------------------------
/test-requirements.txt:
--------------------------------------------------------------------------------
1 | yamllint
2 |
--------------------------------------------------------------------------------
/tests/deploy-minikube.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | # shellcheck disable=SC1090
4 | source "$(dirname "$0")"/../pattern-ci/scripts/resources.sh
5 |
6 | kubectl_deploy() {
7 | echo "Running scripts/quickstart.sh"
8 | "$(dirname "$0")"/../scripts/quickstart.sh
9 |
10 | echo "Waiting for pods to be running..."
11 | i=0
12 | while [[ $(kubectl get pods -l app=wordpress | grep -c Running) -ne 2 ]]; do
13 | if [[ ! "$i" -lt 24 ]]; then
14 | echo "Timeout waiting on pods to be ready"
15 | test_failed "$0"
16 | fi
17 | sleep 10
18 | echo "...$i * 10 seconds elapsed..."
19 | ((i++))
20 | done
21 | kubectl get pods
22 | echo "All pods are running"
23 | }
24 |
25 | verify_deploy(){
26 | echo "Verifying deployment..."
27 | kubectl get services
28 | sleep 60
29 | if ! curl -sS "$(minikube service --url wordpress)"; then
30 | test_failed "$0"
31 | fi
32 | }
33 |
34 | main(){
35 | if ! kubectl_deploy; then
36 | test_failed "$0"
37 | elif ! verify_deploy; then
38 | test_failed "$0"
39 | else
40 | test_passed "$0"
41 | fi
42 | }
43 |
44 | main
45 |
--------------------------------------------------------------------------------
/tests/test-kubernetes.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # This script is intended to be run by Travis CI. If running elsewhere, invoke
4 | # it with: TRAVIS_PULL_REQUEST=false [path to script]
5 | # CLUSTER_NAME must be set prior to running (see environment variables in the
6 | # Travis CI documentation).
7 |
8 | # shellcheck disable=SC1090
9 | source "$(dirname "$0")"/../scripts/resources.sh
10 |
11 | kubectl_clean() {
12 | echo "Cleaning cluster"
13 | kubectl delete --ignore-not-found=true svc,pvc,deployment -l app=wordpress
14 | kubectl delete --ignore-not-found=true secret mysql-pass
15 | kubectl delete --ignore-not-found=true -f local-volumes.yaml
16 | kuber=$(kubectl get pods -l app=wordpress)
17 | while [ ${#kuber} -ne 0 ]
18 | do
19 | sleep 5s
20 | kubectl get pods -l app=wordpress
21 | kuber=$(kubectl get pods -l app=wordpress)
22 | done
23 | }
24 |
25 | kubectl_config() {
26 | echo "Configuring kubectl"
27 | #shellcheck disable=SC2091
28 | $(bx cs cluster-config "$CLUSTER_NAME" | grep export)
29 | }
30 |
31 | kubectl_deploy() {
32 | kubectl_clean
33 |
34 | echo "Modifying yaml files to ignore storage-class"
35 | sed -i '$!N;/PersistentVolumeClaim.*\n.*metadata/a \ \ annotations: \n\ \ \ \ volume.beta.kubernetes.io/storage-class: ""' mysql-deployment.yaml
36 | sed -i '$!N;/PersistentVolumeClaim.*\n.*metadata/a \ \ annotations: \n\ \ \ \ volume.beta.kubernetes.io/storage-class: ""' wordpress-deployment.yaml
37 |
38 | echo "Running scripts/quickstart.sh"
39 | "$(dirname "$0")"/../scripts/quickstart.sh
40 |
41 | echo "Waiting for pods to be running..."
42 | i=0
43 | while [[ $(kubectl get pods -l app=wordpress | grep -c Running) -ne 2 ]]; do
44 | if [[ ! "$i" -lt 24 ]]; then
45 | echo "Timeout waiting on pods to be ready"
46 | test_failed "$0"
47 | fi
48 | sleep 10
49 | echo "...$i * 10 seconds elapsed..."
50 | ((i++))
51 | done
52 | echo "All pods are running"
53 | sleep 30
54 | }
55 |
56 | verify_deploy() {
57 | echo "Verifying deployment was successful"
58 | IPS=$(bx cs workers "$CLUSTER_NAME" | awk '{ print $2 }' | grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}')
59 | for IP in $IPS; do
60 | if ! curl -sS http://"$IP":30180/version; then
61 | test_failed "$0"
62 | fi
63 | done
64 | }
65 |
66 | main(){
67 | is_pull_request "$0"
68 |
69 | if ! kubectl_config; then
70 | test_failed "$0"
71 | elif ! kubectl_deploy; then
72 | test_failed "$0"
73 | elif ! verify_deploy; then
74 | test_failed "$0"
75 | else
76 | test_passed "$0"
77 | kubectl_clean
78 | fi
79 | }
80 |
81 | main
82 |
--------------------------------------------------------------------------------
/wordpress-deployment-compose.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: wordpress-c
6 | labels:
7 | app: wordpress-c
8 | spec:
9 | ports:
10 | - port: 80
11 | selector:
12 | app: wordpress-c
13 | tier: frontend-c
14 | type: NodePort
15 | ---
16 | apiVersion: v1
17 | kind: PersistentVolumeClaim
18 | metadata:
19 | name: wpc-pv-claim
20 | labels:
21 | app: wordpress-c
22 | spec:
23 | accessModes:
24 | - ReadWriteOnce
25 | resources:
26 | requests:
27 | storage: 20Gi
28 | ---
29 | apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
30 | kind: Deployment
31 | metadata:
32 | name: wordpress-c
33 | labels:
34 | app: wordpress-c
35 | spec:
36 | selector:
37 | matchLabels:
38 | app: wordpress-c
39 | tier: frontend-c
40 | strategy:
41 | type: Recreate
42 | template:
43 | metadata:
44 | labels:
45 | app: wordpress-c
46 | tier: frontend-c
47 | spec:
48 | containers:
49 | - image: wordpress:latest
50 | name: wordpress-c
51 | env:
52 | - name: WORDPRESS_DB_HOST
53 | value: <>:<>
54 | - name: WORDPRESS_DB_USER
55 | value: <>
56 | - name: WORDPRESS_DB_PASSWORD
57 | value: <>
58 | ports:
59 | - containerPort: 80
60 | name: wordpress-c
61 | volumeMounts:
62 | - name: wordpress-c-persistent-storage
63 | mountPath: /var/www/html
64 | volumes:
65 | - name: wordpress-c-persistent-storage
66 | persistentVolumeClaim:
67 | claimName: wpc-pv-claim
68 |
--------------------------------------------------------------------------------
/wordpress-deployment.yaml:
--------------------------------------------------------------------------------
1 | ---
2 | apiVersion: v1
3 | kind: Service
4 | metadata:
5 | name: wordpress
6 | labels:
7 | app: wordpress
8 | tier: frontend
9 | spec:
10 | ports:
11 | - port: 80
12 | selector:
13 | app: wordpress
14 | tier: frontend
15 | type: NodePort
16 | ---
17 | apiVersion: v1
18 | kind: PersistentVolume
19 | metadata:
20 | name: wp-pv-volume
21 | labels:
22 | type: local
23 | spec:
24 | storageClassName: manual
25 | capacity:
26 | storage: 20Gi
27 | accessModes:
28 | - ReadWriteOnce
29 | hostPath:
30 | path: "/tmp/wp/data"
31 | persistentVolumeReclaimPolicy: Recycle
32 | ---
33 | apiVersion: v1
34 | kind: PersistentVolumeClaim
35 | metadata:
36 | name: wp-pv-claim
37 | labels:
38 | app: wordpress
39 | spec:
40 | storageClassName: manual
41 | accessModes:
42 | - ReadWriteOnce
43 | resources:
44 | requests:
45 | storage: 20Gi
46 | ---
47 | apiVersion: apps/v1 # versions before 1.9.0 use apps/v1beta2
48 | kind: Deployment
49 | metadata:
50 | name: wordpress
51 | labels:
52 | app: wordpress
53 | tier: frontend
54 | spec:
55 | selector:
56 | matchLabels:
57 | app: wordpress
58 | tier: frontend
59 | strategy:
60 | type: Recreate
61 | template:
62 | metadata:
63 | labels:
64 | app: wordpress
65 | tier: frontend
66 | spec:
67 | containers:
68 | - image: wordpress:5.8.1-php7.4
69 | name: wordpress
70 | env:
71 | - name: WORDPRESS_DB_HOST
72 | value: wordpress-mysql
73 | - name: WORDPRESS_DB_NAME
74 | value: wordpress
75 | - name: WORDPRESS_DB_USER
76 | value: root
77 | - name: WORDPRESS_DB_PASSWORD
78 | valueFrom:
79 | secretKeyRef:
80 | name: mysql-pass
81 | key: password
82 | ports:
83 | - containerPort: 80
84 | name: wordpress
85 | volumeMounts:
86 | - name: wordpress-persistent-storage
87 | mountPath: /var/www/html
88 | volumes:
89 | - name: wordpress-persistent-storage
90 | persistentVolumeClaim:
91 | claimName: wp-pv-claim
92 |
--------------------------------------------------------------------------------