Fix phabricator example

This commit is contained in:
Filip Grzadkowski
2015-09-28 14:34:14 +02:00
parent f8a9943d90
commit 4b515db460
8 changed files with 69 additions and 158 deletions

View File

@@ -43,16 +43,36 @@ This example assumes that you have a basic understanding of kubernetes [services
```sh
$ cd kubernetes
$ hack/dev-build-and-up.sh
$ cluster/kube-up.sh
```
### Step One: Set up Cloud SQL instance
Follow the [official instructions](https://cloud.google.com/sql/docs/getting-started) to set up Cloud SQL instance.
In the remaining part of this example we will assume that your instance is named "phabricator-db", has IP 173.194.242.66 and the password is "1234".
In the remaining part of this example we will assume that your instance is named "phabricator-db", has IP 1.2.3.4, is listening on port 3306 and the password is "1234".
### Step Two: Turn up the phabricator
### Step Two: Authenticate phabricator in Cloud SQL
In order to allow phabricator to connect to your Cloud SQL instance you need to run the following command to authorize all your nodes within a cluster:
```bash
NODE_NAMES=`kubectl get nodes | cut -d" " -f1 | tail -n+2`
NODE_IPS=`gcloud compute instances list $NODE_NAMES | tr -s " " | cut -d" " -f 5 | tail -n+2`
gcloud sql instances patch phabricator-db --authorized-networks $NODE_IPS
```
Otherwise you will see the following logs:
```bash
$ kubectl logs phabricator-controller-02qp4
[...]
Raw MySQL Error: Attempt to connect to root@1.2.3.4 failed with error
#2013: Lost connection to MySQL server at 'reading initial communication packet', system error: 0.
```
### Step Three: Turn up the phabricator
To start Phabricator server use the file [`examples/phabricator/phabricator-controller.json`](phabricator-controller.json) which describes a [replication controller](../../docs/user-guide/replication-controller.md) with a single [pod](../../docs/user-guide/pods.md) running an Apache server with Phabricator PHP source:
@@ -89,6 +109,20 @@ To start Phabricator server use the file [`examples/phabricator/phabricator-cont
"name": "http-server",
"containerPort": 80
}
],
"env": [
{
"name": "MYSQL_SERVICE_IP",
"value": "1.2.3.4"
},
{
"name": "MYSQL_SERVICE_PORT",
"value": "3306"
},
{
"name": "MYSQL_PASSWORD",
"value": "1234"
}
]
}
]
@@ -107,6 +141,8 @@ Create the phabricator pod in your Kubernetes cluster by running:
$ kubectl create -f examples/phabricator/phabricator-controller.json
```
**Note:** Remember to substitute environment variable values in json file before create replication controller.
Once that's up you can list the pods in the cluster, to verify that it is running:
```sh
@@ -132,84 +168,11 @@ CONTAINER ID IMAGE COMMAND CREATED
(Note that initial `docker pull` may take a few minutes, depending on network conditions. During this time, the `get pods` command will return `Pending` because the container has not yet started )
### Step Three: Authenticate phabricator in Cloud SQL
If you read logs of the phabricator container you will notice the following error message:
```bash
$ kubectl logs phabricator-controller-02qp4
[...]
Raw MySQL Error: Attempt to connect to root@173.194.252.142 failed with error
#2013: Lost connection to MySQL server at 'reading initial communication packet', system error: 0.
```
This is because the host on which this container is running is not authorized in Cloud SQL. To fix this run:
```bash
gcloud sql instances patch phabricator-db --authorized-networks 130.211.141.151
```
To automate this process and make sure that a proper host is authorized even if pod is rescheduled to a new machine we need a separate pod that periodically lists pods and authorizes hosts. Use the file [`examples/phabricator/authenticator-controller.json`](authenticator-controller.json):
<!-- BEGIN MUNGE: EXAMPLE authenticator-controller.json -->
```json
{
"kind": "ReplicationController",
"apiVersion": "v1",
"metadata": {
"name": "authenticator-controller",
"labels": {
"name": "authenticator"
}
},
"spec": {
"replicas": 1,
"selector": {
"name": "authenticator"
},
"template": {
"metadata": {
"labels": {
"name": "authenticator"
}
},
"spec": {
"containers": [
{
"name": "authenticator",
"image": "gcr.io/google_containers/cloudsql-authenticator:v1"
}
]
}
}
}
}
```
[Download example](authenticator-controller.json?raw=true)
<!-- END MUNGE: EXAMPLE authenticator-controller.json -->
To create the pod run:
```sh
$ kubectl create -f examples/phabricator/authenticator-controller.json
```
### Step Four: Turn up the phabricator service
A Kubernetes 'service' is a named load balancer that proxies traffic to one or more containers. The services in a Kubernetes cluster are discoverable inside other containers via *environment variables*. Services find the containers to load balance based on pod labels. These environment variables are typically referenced in application code, shell scripts, or other places where one node needs to talk to another in a distributed system. You should catch up on [kubernetes services](../../docs/user-guide/services.md) before proceeding.
The pod that you created in Step One has the label `name=phabricator`. The selector field of the service determines which pods will receive the traffic sent to the service. Since we are setting up a service for an external application we also need to request external static IP address (otherwise it will be assigned dynamically):
```sh
$ gcloud compute addresses create phabricator --region us-central1
Created [https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1/addresses/phabricator].
NAME REGION ADDRESS STATUS
phabricator us-central1 107.178.210.6 RESERVED
```
The pod that you created in Step Three has the label `name=phabricator`. The selector field of the service determines which pods will receive the traffic sent to the service.
Use the file [`examples/phabricator/phabricator-service.json`](phabricator-service.json):
@@ -247,16 +210,25 @@ $ kubectl create -f examples/phabricator/phabricator-service.json
phabricator
```
To play with the service itself, find the `EXTERNAL_IP` of the load balancer:
To play with the service itself, find the external IP of the load balancer:
```console
$ kubectl get services phabricator
NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE
phabricator 10.0.0.2 1.2.3.4 8080/TCP ... ...
$ kubectl get services
NAME LABELS SELECTOR IP(S) PORT(S)
kubernetes component=apiserver,provider=kubernetes <none> 10.0.0.1 443/TCP
phabricator <none> name=phabricator 10.0.31.173 80/TCP
$ kubectl get services phabricator -o json | grep ingress -A 4
"ingress": [
{
"ip": "104.197.13.125"
}
]
```
and then visit port 80 of that IP address.
**Note**: Provisioning of the external IP address may take few minutes.
**Note**: You may need to open the firewall for port 80 using the [console][cloud-console] or the `gcloud` tool. The following command will allow traffic from any source to instances tagged `kubernetes-minion`:
```sh