Skip to content

Commit

Permalink
Update kubernetes api demo to use kubernetes api (#294)
Browse files Browse the repository at this point in the history
* Update kubernetes api demo to use kubernetes api
  • Loading branch information
chbatey authored Sep 14, 2018
1 parent dae4550 commit 3bbff39
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 258 deletions.
34 changes: 7 additions & 27 deletions bootstrap-demo/kubernetes-api/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,17 @@ import com.typesafe.sbt.packager.docker._

enablePlugins(JavaServerAppPackaging)

dockerEntrypoint ++= Seq(
"""-Dakka.remote.netty.tcp.hostname="$(eval "echo $AKKA_REMOTING_BIND_HOST")"""",
"""-Dakka.management.http.hostname="$(eval "echo $AKKA_REMOTING_BIND_HOST")""""
)

/*
libraryDependencies += Seq(
// 1) we want to use akka-management
"akka-management",
// 2) we want to use the bootstrap
"akka-management-cluster-bootstrap",
// 3) the initial contact points should be located via DNS:
"akka-discovery-dns",
// extra)
// ""akka-management-cluster-http" // optional, if you want to inspect the cluster as well
*/
version := "1.3.3.7" // we hard-code the version here, it could be anything really

dockerCommands :=
dockerCommands.value.flatMap {
case ExecCmd("ENTRYPOINT", args @ _*) => Seq(Cmd("ENTRYPOINT", args.mkString(" ")))
case v => Seq(v)
}
dockerExposedPorts := Seq(8080, 8558, 2552)
dockerBaseImage := "openjdk:8-jre-alpine"

version := "1.3.3.7" // we hard-code the version here, it could be anything really

// ENABLE THESE IF YOU WANT TO MANUALLY DO DNSLOOKUPS IN THE CONTAINER (FOR DEBUGGING)
//dockerCommands ++= Seq(
// Cmd("USER", "root")
// ExecCmd("RUN", "apt-get", "update"),
// ExecCmd("RUN", "apt-get", "install", "-y", "dnsutils")
//)
dockerCommands ++= Seq(
Cmd("USER", "root"),
Cmd("RUN", "/sbin/apk", "add", "--no-cache", "bash", "bind-tools", "busybox-extras", "curl", "strace")
)
3 changes: 0 additions & 3 deletions bootstrap-demo/kubernetes-api/kube-create.sh

This file was deleted.

4 changes: 0 additions & 4 deletions bootstrap-demo/kubernetes-api/kube-delete.sh

This file was deleted.

30 changes: 0 additions & 30 deletions bootstrap-demo/kubernetes-api/kube-logs.sh

This file was deleted.

39 changes: 2 additions & 37 deletions bootstrap-demo/kubernetes-api/kubernetes/akka-cluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
app: appka
name: appka
spec:
replicas: 4
replicas: 2
selector:
matchLabels:
app: appka
Expand All @@ -17,14 +17,8 @@ spec:
spec:
containers:
- name: appka
image: ktoso/akka-management-bootstrap-joining-demo-kubernetes-api:1.3.3.7
image: bootstrap-demo-kubernetes-api:1.3.3.7
imagePullPolicy: Never
env:
- name: HOST_NAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
livenessProbe:
tcpSocket:
port: 8558
Expand All @@ -42,35 +36,6 @@ spec:
containerPort: 8558
protocol: TCP
---
kind: Service
apiVersion: v1
metadata:
name: appka-service
spec:
# by setting the clusterIp to None we are a "headless service"
# and thus the svc ("service") DNS record for the single IP but the IPs of all nodes that we select
#
# In other words:
# $ kubectl exec -it $POD -- nslookup appka-service.default.svc.cluster.local
# Server: 10.0.0.10
# Address: 10.0.0.10#53
#
# Name: appka-service.default.svc.cluster.local
# Address: 172.17.0.7
# Name: appka-service.default.svc.cluster.local
# Address: 172.17.0.8
# Name: appka-service.default.svc.cluster.local
# Address: 172.17.0.9
# Name: appka-service.default.svc.cluster.local
# Address: 172.17.0.6
clusterIP: None
selector:
app: appka
ports:
- protocol: TCP
port: 8558
targetPort: 8558
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
Expand Down
49 changes: 16 additions & 33 deletions bootstrap-demo/kubernetes-api/src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,38 +1,21 @@
akka {
#discovery-config
akka.discovery {
# pick the discovery method you'd like to use:
method = kubernetes-api

actor {
provider = "cluster"
kubernetes-api {
pod-label-selector = "actorSystemName=%s"
}

discovery {
# pick the discovery method you'd like to use:
method = kubernetes-api

kubernetes-api {
pod-label-selector = "actorSystemName=appka"
}
}

management {
http {
port = 8558
}

cluster.bootstrap {

contact-point-discovery {
service-name = "appka-service"
service-namespace = "default.svc.cluster.local"
stable-margin = 5 seconds
}

contact-point {
# currently this port HAS TO be the same as the `akka.management.http.port`
# it would not have to be once we implement the SRV record watching, since then we could potentially
# get the ports from the DNS records.
fallback-port = 8558
}
}
#discovery-config

#management-config
akka.management {
cluster.bootstrap {
contact-point-discovery {
# For the kubernetes API this value is substributed into the %s in pod-label-selector
service-name = "appka"
}
}

}
#management-config
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ object DemoApp extends App {
import akka.http.scaladsl.server.Directives._
Http().bindAndHandle(complete("Hello world"), "0.0.0.0", 8080)

Cluster(system).registerOnMemberUp({
log.info("Cluster member is up!")
})

}

class ClusterWatcher extends Actor with ActorLogging {
Expand Down
2 changes: 1 addition & 1 deletion bootstrap-demo/kubernetes-dns/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import com.typesafe.sbt.packager.docker._

enablePlugins(JavaServerAppPackaging)

version := "1.3.3.7" // we hard-code the version here, it could be anything really
dockerCommands :=
dockerCommands.value.flatMap {
case ExecCmd("ENTRYPOINT", args @ _*) => Seq(Cmd("ENTRYPOINT", args.mkString(" ")))
case v => Seq(v)
}

version := "1.3.3.7" // we hard-code the version here, it could be anything really

dockerExposedPorts := Seq(8080, 8558, 2552)
dockerBaseImage := "openjdk:8-jre-alpine"
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ lazy val `cluster-bootstrap` = project
.dependsOn(`akka-management`, `akka-discovery`)

lazy val `bootstrap-demo-kubernetes-api` = project
.in(file("bootstrap-joining-demo/kubernetes-api"))
.in(file("bootstrap-demo/kubernetes-api"))
.enablePlugins(NoPublish)
.disablePlugins(BintrayPlugin)
.enablePlugins(AutomateHeaderPlugin)
Expand Down
11 changes: 0 additions & 11 deletions docs/src/main/paradox/bootstrap/demos/index.md

This file was deleted.

95 changes: 0 additions & 95 deletions docs/src/main/paradox/bootstrap/demos/kubernetes-api.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/src/main/paradox/bootstrap/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ is strictly defined and is as follows:
to be using the Bootstrap mechanism.
@@@

## Demos
## Bootstrap recipes

To see how to use bootstrap in various environments such as Kubernetes see @ref[demos](./demos/index.md)
To see how to use bootstrap in various environments such as Kubernetes see @ref[recipes](recipes.md)


Loading

0 comments on commit 3bbff39

Please sign in to comment.