Skip to content

Commit

Permalink
Added commands to run project locally in README.md; fixed image name …
Browse files Browse the repository at this point in the history
…in statefulset.yaml; added logging instead of println
  • Loading branch information
sharma-rohit committed Feb 25, 2018
1 parent eb68724 commit 941cfc4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 31 deletions.
19 changes: 0 additions & 19 deletions Dockerfile

This file was deleted.

42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# -distributed-cache-on-k8s-poc
[PoC] Distributed Cache with Akka Cluster Sharding and Akka HTTP on Kubernetes and AWS
# distributed-cache-on-k8s-poc
[PoC] Distributed Cache with Akka Cluster Sharding and Akka HTTP on Kubernetes

# Running it locally (On Mac) with docker images from local registry

`git clone https://github.com/sharma-rohit/distributed-cache-on-k8s-poc.git`

1. Install minikube: `brew cask install minikube`
2. Inatall kubectl: `brew install kubectl`
3. Start minikube with --insecure-registry option:

`minikube start --insecure-registry localhost:5000`
4. Setup minikube Ingress controller:

`minikube addons enable ingress`
5. To make the local `docker` command use the minikube vm as docker host and all commands starting with `docker` affecting the minikube vm not the host computer run:

`eval $(minikube docker-env)`

6. `docker run -d -p 5000:5000 --restart=always --name registry -v /data/docker-registry:/var/lib/registry registry:2`

7. To build and publish docker image to local registry of minikube run:

`sbt docker:publish`

8. Create kubernetes manifests:

`kubectl create -f kubernetes/statefulset.yaml`

`kubectl apply -f kubernetes/service.yaml`

`kubectl apply -f kubernetes/headless_service.yaml`

`kubectl apply -f kubernetes/ingress.yaml`

9. To redirect traffic from the domain "distributed-cache.com" stated in ingress.yaml to our minikube cluster run:

`echo "$(minikube ip) distributed-cache.com" | sudo tee -a /etc/hosts`


14 changes: 12 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ version := "1.0"

scalaVersion := "2.12.1"

lazy val root = (project in file("."))
.enablePlugins(JavaAppPackaging, DockerPlugin)

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % "10.0.10",
"com.typesafe.akka" %% "akka-cluster" % "2.5.9",
"com.typesafe.akka" %% "akka-cluster-sharding" % "2.5.9",
"org.slf4j" % "slf4j-simple" % "1.7.25" % Test
)
"org.slf4j" % "slf4j-simple" % "1.7.25" % Test,
"com.spotify" % "docker-client" % "3.5.13"
)

maintainer in Docker := "rohitsharma9204@gmail.com"
dockerBaseImage := "openjdk:8"
dockerRepository := Some("localhost:5000")
dockerExposedPorts:= Seq(9000)
daemonUser in Docker := "root"
2 changes: 1 addition & 1 deletion kubernetes/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ spec:
spec:
containers:
- name: distributed-cache
image: "localhost:5000/distributed-cache:0.2.0"
image: "localhost:5000/distributed-cache-on-k8s-poc:1.0"
env:
- name: AKKA_ACTOR_SYSTEM_NAME
value: "distributed-cache-system"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version = 0.13.17
sbt.version = 1.1.0
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.3")
9 changes: 4 additions & 5 deletions src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import akka.actor.ActorSystem
import akka.event.Logging
import akka.http.scaladsl.Http
import akka.stream.{ ActorMaterializer, ActorMaterializerSettings }
import cluster.ClusterStateInformer
Expand All @@ -11,7 +12,6 @@ import scala.concurrent.ExecutionContext.Implicits.global
object Main {

def main(args: Array[String]): Unit = {
println("Starting containers.....")
val config: Config = {
import scala.collection.JavaConverters._
val seedNodes = ClusterSetup.seedNodes()
Expand All @@ -23,14 +23,13 @@ object Main {
.resolve()
}

println(config)

implicit val system: ActorSystem = ActorSystem(ClusterSetup.actorSystemName(), config)
val logging = Logging(system, "main")
implicit val mat = ActorMaterializer(materializerSettings = Some(ActorMaterializerSettings(system)))
val routes = new Route(system)
Http().bindAndHandle(routes.routes, "0.0.0.0", 9000).onComplete {
case Success(s) => println("Successfully started..")
case Failure(f) => println(f)
case Success(s) => logging.info("Successfully started")
case Failure(f) => logging.error(f, "Server cannot be started!!!!")
}

system.actorOf(ClusterStateInformer.props(), "cluster-informer")
Expand Down

0 comments on commit 941cfc4

Please sign in to comment.