Commit 007a5dda authored by mengxue's avatar mengxue
Browse files

Build a nginx ingress controller object

parent af5961dc
......@@ -4,10 +4,10 @@ import java.text.SimpleDateFormat
import java.util.concurrent.Executors
import skuber._
import skuber.json.format._
import skuber.apps.v1.{Deployment, DeploymentList}
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber.apps.v1.{Deployment, DeploymentList}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.{Failure, Success}
......@@ -49,7 +49,7 @@ object DeleteDeployment extends App {
System.out.println(f"${name}%-25s${ns}%-20s" +
f"${deploymentInfo.map{_.availableReplicas}.getOrElse("None")}"+"/"+ f"${deploymentInfo.map{_.replicas}.getOrElse("None")}%-18s" +
f"${deploymentInfo.map{_.updatedReplicas}.getOrElse("<None>")}%-20s" +
f"${deploymentInfo.map{_.updatedReplicas}.getOrElse("None")}%-20s" +
f"${deploymentInfo.map{_.availableReplicas}.getOrElse("None")}%-20s" +
f"${createTimeString}")
}
......@@ -88,7 +88,7 @@ object DeleteDeployment extends App {
system.terminate()
materializer.shutdown()
} else {
System.out.println("\nDeleting the deployment <" + deleteDeploymentName + ">...")
System.out.println("\nDeleting the deployment \"" + deleteDeploymentName + "\"...")
val deleteOptions = DeleteOptions(propagationPolicy = Some(DeletePropagation.Foreground))
val deleteFut = k8s.deleteWithOptions[Deployment](deleteDeploymentName, deleteOptions)
......@@ -96,7 +96,7 @@ object DeleteDeployment extends App {
deleteFut onComplete { delete =>
delete match {
case Success(_) =>
println("\nSuccessfully deleted the deployment <" + deleteDeploymentName + ">")
println("\nSuccessfully deleted the deployment \"" + deleteDeploymentName + "\"")
case Failure(ex) =>
System.err.println("Failed => " + ex)
}
......
package skuberopenmole
import skuber.{DeleteOptions, DeletePropagation, Service, ServiceList, Timestamp, k8sInit}
import java.text.SimpleDateFormat
import java.util.concurrent.Executors
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber.Service.Type.ServiceType
import skuber._
import scala.util.{Failure, Success}
import skuber._
import skuber.json.format._
import skuber.{DeleteOptions, DeletePropagation, Timestamp, k8sInit}
import scala.util.{Failure, Success}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
......@@ -21,6 +19,7 @@ import scala.concurrent.duration._
* @author Mengxue
*
* Delete a pod in kubernetes cluster
* The old pod will be deleted and a new pod will automatically be created
*/
object DeletePod extends App{
......@@ -89,7 +88,7 @@ object DeletePod extends App{
system.terminate()
materializer.shutdown()
} else {
System.out.println("\nDeleting the pod <" + deletePodName + ">...")
System.out.println("\nDeleting the pod \"" + deletePodName + "\"...")
val deleteOptions = DeleteOptions(propagationPolicy = Some(DeletePropagation.Foreground))
val deleteFut = k8s.deleteWithOptions[Pod](deletePodName, deleteOptions)
......@@ -97,7 +96,7 @@ object DeletePod extends App{
deleteFut onComplete { delete =>
delete match {
case Success(_) =>
println("\nSuccessfully deleted pod <" + deletePodName + ">")
println("\nSuccessfully deleted pod \"" + deletePodName + "\"")
case Failure(ex) =>
System.err.println("Failed => " + ex)
}
......
package skuberopenmole
import skuber.{DeleteOptions, DeletePropagation, Service, ServiceList, Timestamp, k8sInit}
import java.text.SimpleDateFormat
import java.util.concurrent.Executors
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber.Service.Type.ServiceType
import skuber._
import scala.util.{Failure, Success}
import skuber.json.format._
import skuber.{DeleteOptions, DeletePropagation, Service, ServiceList, Timestamp, k8sInit}
import scala.util.{Failure, Success}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
/**
* @author Mengxue
*
......@@ -67,8 +65,8 @@ object DeleteService extends App{
val createTimeString = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(clusterInfo.map{_.createTime}.getOrElse("None").toString())
System.out.println(f"${name}%-25s${ns}%-20s" +
f"${clusterInfo.map{_.clusterType.toString}.getOrElse("<None>")}%-20s" +
f"${clusterInfo.map{_.clusterIp.toString}.getOrElse("<None>")}%-20s" +
f"${clusterInfo.map{_.clusterType.toString}.getOrElse("None")}%-20s" +
f"${clusterInfo.map{_.clusterIp.toString}.getOrElse("None")}%-20s" +
f"${clusterInfo.map{_.externalIp.headOption}.getOrElse("None")}%-20s" +
f"${createTimeString}%-35s" +
f"${clusterInfo.map{_.ports.mkString(",")}.getOrElse("None")}" + "/" +
......@@ -109,7 +107,7 @@ object DeleteService extends App{
system.terminate()
materializer.shutdown()
} else {
System.out.println("\nDeleting the service <" + deleteServiceName + ">...")
System.out.println("\nDeleting the service \"" + deleteServiceName + "\"...")
val deleteOptions = DeleteOptions(propagationPolicy = Some(DeletePropagation.Foreground))
val deleteFut = k8s.deleteWithOptions[Service](deleteServiceName, deleteOptions)
......
......@@ -30,7 +30,7 @@ object DeploymentOpenmole extends App {
deployment.onComplete { depl =>
depl match {
case Success(value) => println("\nSuccessfully created deployment of openmole : <" + openmoleDeploymentName + ">")
case Success(_) => println("\nSuccessfully created deployment of openmole : <" + openmoleDeploymentName + ">")
case Failure(exception) => exception.printStackTrace()
}
k8s.close
......@@ -49,7 +49,7 @@ object DeploymentOpenmole extends App {
.addContainer(openmoleContainer)
.addLabel(openmoleLabel)
val desiredCount = 2
val desiredCount = 1
val openmoleDeployment = Deployment(openmoleDeploymentName)
.withReplicas(desiredCount)
.withTemplate(openmoleTemplate)
......
......@@ -7,16 +7,12 @@ import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber._
import skuber.Timestamp
import scala.util.{Failure, Success}
import skuber.Pod.Phase
import skuber.json.format._
import skuberopenmole.DeploymentOpenmole.system
import scala.util.{Failure, Success}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
/**
* @author Mengxue
*
......
......@@ -5,12 +5,12 @@ import java.util.concurrent.Executors
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import skuber.Service.Type.ServiceType
import skuber._
import scala.util.{Failure, Success}
import skuber._
import skuber.json.format._
import skuber.Service.Type.ServiceType
import scala.util.{Failure, Success}
import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
......
package skuberopenmole
import skuber._
import skuber.ext.{Ingress, ReplicaSet}
/**
* @author Mengxue
*/
object NginxIngress extends App {
val httpPort = 80
val httpsPort = 443
val nodeIngressHttpPort = 30000
val nodeIngressHttpsPort = 30443
/**
* Build an nginx ingress controller object
*
* @return a replica set object that can be created on Kubernetes to get the controller running on the cluster.
*/
def buildIngressController: (Service, ReplicaSet) = {
val replicaSet = 1
val name = "skuber-nginx-ing-ctrlr"
val ingressControllerPodLabel = "skuber-example-app" -> "nginx-ingress-lb"
val controllerImage = "gcr.io/google_containers/nginx-ingress-controller:0.7"
val nginxContainer = Container(name = name, image = controllerImage)
.withImagePullPolicy(Container.PullPolicy.Always)
.withHttpLivenessProbe("/healthz", 10249, initialDelaySeconds = 30, timeoutSeconds = 5)
.setEnvVarFromField("POD_NAME", "metadata.name")
.setEnvVarFromField("POD_NAMESPACE", "metadata.namespace")
.exposePort(httpPort)
.exposePort(httpsPort)
.withArgs(
"/nginx-ingress-controller",
"--default-backend-service=default/default-http-backend"
)
val podSpec = Pod.Spec()
.addContainer(nginxContainer)
.withTerminationGracePeriodSeconds(60)
val rset = ReplicaSet(name = name, podSpec = podSpec, labels = Map(ingressControllerPodLabel))
val svc = Service(name)
.withSelector(ingressControllerPodLabel)
.exposeOnNodePort(nodeIngressHttpPort -> httpPort, "http")
.exposeOnNodePort(nodeIngressHttpsPort -> httpsPort, "https")
(svc, rset)
}
/**
* Build a simple ingress objects that encapsulates some rules for routing HTTP traffic coming into the cluster
*
* @return
*/
def buildIngress: Ingress = {
Ingress("echomap")
.addHttpRule("foo.bar.com", Map("/foo" -> "echoheaders-x:80"))
.addHttpRule("bar.baz.com", Map("/bar" -> "echoheaders-y:80", "/foo" -> "echoheaders-x:80"))
}
}
......@@ -10,7 +10,6 @@ import scala.concurrent.Future
/**
* @author Mengxue
*
*/
object ServiceOpenmole extends App {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment