Skip to content

Commit a9976e8

Browse files
authored
Merge pull request #147 from Altinity/0.4.4
Service handling modificatons and repilcation docs enhancements
2 parents 11c7400 + 4502b8e commit a9976e8

10 files changed

+102
-28
lines changed

Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
FROM golang:1.12.7 AS builder
44

5-
RUN apt-get update && apt-get install -y -q apt-utils && apt-get install -y -q gettext-base
6-
WORKDIR $GOPATH/src/github.com/altinity/clickhouse-operator
5+
RUN apt-get update && apt-get install -y apt-utils gettext-base
76

87
# Reconstruct source tree inside docker
8+
WORKDIR $GOPATH/src/github.com/altinity/clickhouse-operator
99
ADD . .
1010
# ./vendor is excluded in .dockerignore, reconstruct it with 'dep' tool
1111
RUN go get -u github.com/golang/dep/cmd/dep
@@ -16,9 +16,11 @@ RUN OPERATOR_BIN=/tmp/clickhouse-operator ./dev/binary_build.sh
1616

1717
# === Runner ===
1818

19-
FROM alpine:3.8 AS runner
20-
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
19+
FROM alpine:3.10 AS runner
20+
21+
RUN apk add --no-cache ca-certificates
2122
WORKDIR /
2223
COPY --from=builder /tmp/clickhouse-operator .
23-
ENTRYPOINT ["./clickhouse-operator"]
24+
25+
ENTRYPOINT ["/clickhouse-operator"]
2426
CMD ["-alsologtostderr=true", "-v=1"]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
apiVersion: "clickhouse.altinity.com/v1"
2+
kind: "ClickHouseInstallation"
3+
4+
metadata:
5+
name: "repl-05"
6+
7+
spec:
8+
defaults:
9+
templates:
10+
volumeClaimTemplate: default
11+
podTemplate: clickhouse:19.6
12+
13+
configuration:
14+
zookeeper:
15+
nodes:
16+
- host: zookeeper.zoo1ns
17+
clusters:
18+
- name: replicated
19+
layout:
20+
shardsCount: 2
21+
replicasCount: 2
22+
23+
templates:
24+
volumeClaimTemplates:
25+
- name: default
26+
spec:
27+
accessModes:
28+
- ReadWriteOnce
29+
resources:
30+
requests:
31+
storage: 500Mi
32+
podTemplates:
33+
- name: clickhouse:19.6
34+
spec:
35+
containers:
36+
- name: clickhouse-pod
37+
image: yandex/clickhouse-server:19.6.2.11
38+

docs/examples/07-rolling-update-stateless-01-initial-position.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ metadata:
44
name: "update-01"
55
spec:
66
configuration:
7-
zookeeper: # Add Zookeeper
8-
nodes:
9-
- host: zookeeper.zoo1ns
107
clusters:
118
- name: "sharded"
129
layout:
1310
shardsCount: 4
14-
# replicasCount: 2 # Enable replication

docs/examples/09-rolling-update-emptydir-01-initial-position.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ spec:
3030
volumes:
3131
- name: clickhouse-storage
3232
emptyDir:
33-
medium: "" #accepted values: empty str (means node's default medium) or Memory
33+
medium: "" # accepted values: empty str (means node's default medium) or "Memory"
3434
sizeLimit: 1Gi

docs/examples/09-rolling-update-emptydir-02-apply-update.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ spec:
3030
volumes:
3131
- name: clickhouse-storage
3232
emptyDir:
33-
medium: "" #accepted values: empty str (means node's default medium) or Memory
33+
medium: "" # accepted values: empty str (means node's default medium) or "Memory"
3434
sizeLimit: 1Gi

docs/examples/98-quota-01.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: ResourceQuota
3+
metadata:
4+
name: test-quotas
5+
namespace: dev
6+
spec:
7+
hard:
8+
pods: 10
9+
services: 10
10+
replicationcontrollers: 10
11+

docs/replication_setup.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
## Prerequisites
55

66
1. ClickHouse operator [installed](operator_installation_details.md)
7-
1. Zookeeper installed as described in [Zookeeper Setup](zookeeper_setup.md)
7+
1. Zookeeper [installed](zookeeper_setup.md)
88

99

1010
## Manifest
1111

12-
The example below creates a cluster with 2 shards and 2 replicas and persistent storage.
12+
Let's take a look on [example](./examples/04-zookeeper-replication-05-simple-PV.yaml), which creates a cluster with 2 shards and 2 replicas and persistent storage.
1313

1414
```yaml
1515
apiVersion: "clickhouse.altinity.com/v1"
1616
kind: "ClickHouseInstallation"
1717

1818
metadata:
19-
name: test
19+
name: "repl-05"
2020

2121
spec:
2222
defaults:
@@ -25,10 +25,9 @@ spec:
2525
podTemplate: clickhouse:19.6
2626

2727
configuration:
28-
zookeeper: # Add Zookeeper
28+
zookeeper:
2929
nodes:
3030
- host: zookeeper.zoo1ns
31-
port: 2181
3231
clusters:
3332
- name: replicated
3433
layout:
@@ -62,7 +61,7 @@ Operator provides set of [macros](https://clickhouse.yandex/docs/en/operations/s
6261
1. `{replica}` -- replica name in the cluster, maps to pod service name
6362
1. `{shard}` -- shard id
6463

65-
ClickHouse also supports internal macros {database} and {table} that maps to current database.table.
64+
ClickHouse also supports internal macros `{database}` and `{table}` that maps to current **database** and **table** respectively.
6665

6766
### Create replicated table
6867

@@ -84,7 +83,7 @@ ENGINE = Distributed('{cluster}', default, events_local, rand());
8483

8584
We can generate some data:
8685
```sql
87-
insert into events select today(), rand()%3, number, 'my title' from numbers(100);
86+
INSERT INTO events SELECT today(), rand()%3, number, 'my title' FROM numbers(100);
8887
```
8988

9089
And check how these data are distributed over the cluster

pkg/controller/chi/creators.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ func (c *Controller) ReconcileService(service *core.Service) error {
7878

7979
if curService != nil {
8080
// Object with such name already exists, this is not an error
81+
glog.V(1).Infof("Update Service %s/%s", service.Namespace, service.Name)
82+
// spec.resourceVersion is required in order to update Service
83+
service.ResourceVersion = curService.ResourceVersion
84+
// spec.clusterIP field is immutable, need to use already assigned value
85+
// From https://kubernetes.io/docs/concepts/services-networking/service/#defining-a-service
86+
// Kubernetes assigns this Service an IP address (sometimes called the “cluster IP”), which is used by the Service proxies
87+
// See also https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies
88+
// You can specify your own cluster IP address as part of a Service creation request. To do this, set the .spec.clusterIP
89+
service.Spec.ClusterIP = curService.Spec.ClusterIP
90+
_, err := c.kubeClient.CoreV1().Services(service.Namespace).Update(service)
91+
if err != nil {
92+
return err
93+
}
8194
return nil
8295
}
8396

pkg/model/creator.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,28 @@ func (r *Reconciler) createServiceReplica(replica *chiv1.ChiReplica) *corev1.Ser
134134
Spec: corev1.ServiceSpec{
135135
Ports: []corev1.ServicePort{
136136
{
137-
Name: chDefaultHTTPPortName,
138-
Port: chDefaultHTTPPortNumber,
137+
Name: chDefaultHTTPPortName,
138+
Protocol: corev1.ProtocolTCP,
139+
Port: chDefaultHTTPPortNumber,
140+
TargetPort: intstr.FromInt(chDefaultHTTPPortNumber),
139141
},
140142
{
141-
Name: chDefaultClientPortName,
142-
Port: chDefaultClientPortNumber,
143+
Name: chDefaultClientPortName,
144+
Protocol: corev1.ProtocolTCP,
145+
Port: chDefaultClientPortNumber,
146+
TargetPort: intstr.FromInt(chDefaultClientPortNumber),
143147
},
144148
{
145-
Name: chDefaultInterServerPortName,
146-
Port: chDefaultInterServerPortNumber,
149+
Name: chDefaultInterServerPortName,
150+
Protocol: corev1.ProtocolTCP,
151+
Port: chDefaultInterServerPortNumber,
152+
TargetPort: intstr.FromInt(chDefaultInterServerPortNumber),
147153
},
148154
},
149-
Selector: r.labeler.GetSelectorReplicaScope(replica),
150-
ClusterIP: templateDefaultsServiceClusterIP,
151-
Type: "ClusterIP",
155+
Selector: r.labeler.GetSelectorReplicaScope(replica),
156+
ClusterIP: templateDefaultsServiceClusterIP,
157+
Type: "ClusterIP",
158+
PublishNotReadyAddresses: true,
152159
},
153160
}
154161
}
@@ -272,6 +279,14 @@ func (r *Reconciler) setupStatefulSetPodTemplate(statefulSetObject *apps.Statefu
272279
glog.V(1).Infof("createStatefulSetObjects() for statefulSet %s - default template", statefulSetName)
273280
}
274281

282+
// Pod created by this StatefulSet has to have alias
283+
statefulSetObject.Spec.Template.Spec.HostAliases = []corev1.HostAlias{
284+
{
285+
IP: "127.0.0.1",
286+
Hostnames: []string{CreatePodHostname(replica)},
287+
},
288+
}
289+
275290
r.setupConfigMapVolumes(statefulSetObject, replica)
276291
}
277292

release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.3
1+
0.4.4

0 commit comments

Comments
 (0)