Skip to content

Commit

Permalink
add kubernetes support
Browse files Browse the repository at this point in the history
  • Loading branch information
morsh committed Dec 26, 2017
1 parent e68bdfd commit 43f37f6
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 150 deletions.
150 changes: 2 additions & 148 deletions Assets/Scenes/server.unity
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.18028334, g: 0.22571328, b: 0.3069217, a: 1}
m_IndirectSpecularColor: {r: 0.12731704, g: 0.13414727, b: 0.121078536, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -113,152 +113,6 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &605757371
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 605757373}
- component: {fileID: 605757372}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &605757372
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 605757371}
m_Enabled: 1
serializedVersion: 8
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &605757373
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 605757371}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &724782448
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 724782452}
- component: {fileID: 724782451}
- component: {fileID: 724782450}
- component: {fileID: 724782449}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!81 &724782449
AudioListener:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 724782448}
m_Enabled: 1
--- !u!124 &724782450
Behaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 724782448}
m_Enabled: 1
--- !u!20 &724782451
Camera:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 724782448}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_RenderingPath: -1
m_TargetTexture: {fileID: 0}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 1
m_AllowMSAA: 1
m_AllowDynamicResolution: 0
m_ForceIntoRT: 0
m_OcclusionCulling: 1
m_StereoConvergence: 10
m_StereoSeparation: 0.022
--- !u!4 &724782452
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 724782448}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1362603294
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -297,5 +151,5 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
3 changes: 2 additions & 1 deletion Assets/Scripts/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Client : MonoBehaviour {
#region Private Properties
private const int MAX_CONNECTIONS = 100;

private string server_ip = "13.95.69.83"; // "127.0.0.1"
private int port = 5701;

private int hostId;
Expand Down Expand Up @@ -72,7 +73,7 @@ public void Connect()
HostTopology topo = new HostTopology(connectionConfig, MAX_CONNECTIONS);

hostId = NetworkTransport.AddHost(topo, 0);
connectionId = NetworkTransport.Connect(hostId, "127.0.0.1", port, 0, out error);
connectionId = NetworkTransport.Connect(hostId, server_ip, port, 0, out error);

connectionTime = Time.time;
isConnected = true;
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:16.04
RUN useradd -ms /bin/bash unity
WORKDIR /home/unity
COPY builds/Server_Linux/linuxserver.x86_64 /home/unity/
COPY builds/Server_Linux/linuxserver_Data /home/unity/linuxserver_Data/
RUN chown -R unity:unity /home/unity/linuxserver*
USER unity

EXPOSE 7777-7787
ENV SERVERS_REGISTRY_URL http://jpgjsr.azurewebsites.net/api/servers
ENV HEARTBEAT_PERIOD 3

CMD ["./linuxserver.x86_64", "-logFile", "/dev/stdout", "-batchmode", "-nographics"]
3 changes: 2 additions & 1 deletion ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ PlayerSettings:
webGLUseEmbeddedResources: 0
webGLUseWasm: 0
webGLCompressionFormat: 1
scriptingDefineSymbols: {}
scriptingDefineSymbols:
1:
platformArchitecture: {}
scriptingBackend:
Android: 0
Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,46 @@ A sample project to use UNET protocol between client and server to allow multipl

You can also execute the server by opening `Scenes/server` in unity and pressing `Play`.

# Building and Running with Docker

* Open main folder in Unity, open `File > Build Settings`.
* Build `Scenes/desert` into `./Build/Desert/start.exe`.
* Run `Desert/start.exe` multiple times

To build the server

* Open main folder in Unity, open `File > Build Settings`.
* Change build settings to `Linux` + `x86 + x86_x64 (Universal)` + `Headless Mode: true`.
* Open `Player Settings` and set `Scripting Define Symbols` to `CROSS_PLATFORM_INPUT;DEDICATED_SERVER_MODE`.
* Build `Scenes/server` into `./Build/Server/Linux/linuxserver.x86`.
* Build and Run with docker (from root folder):
```sh
docker build -t unitydronesserver:latest .
docker run -p 5701:5701/udp unitydronesserver:latest
```
* Check that the docker container is running:
```sh
docker ps -a
```
* Start multiple clients and connect

# Run on Kubernetes on Azure

You can run **Building and Running with Docker** to create a new image, then run the following commands:
(Replace *<USER_NAME>* with your docker hub user name)
```sh
docker tag unitydronesserver:latest <USER_NAME>/unitydronesserver:latest
docker push <USER_NAME>/unitydronesserver:latest
```

Follow instructions to setup a new kubernetes cluster on Azure under: [k8s/setup.sh](k8s/setup.sh).

Deploy a new application using:
```sh
kubectl create -f k8s/app.yaml
```

If you want to use your own image, change [k8s/app.yaml](k8s/app.yaml) and replace *morshemesh* with your own user name.

# License
MIT License
33 changes: 33 additions & 0 deletions k8s/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Service
metadata:
name: drones-server
labels:
app: drones-server
spec:
type: LoadBalancer
selector:
app: drones-server
ports:
- protocol: UDP
port: 5701
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: drones-server
spec:
strategy:
type: Recreate
template:
metadata:
labels:
app: drones-server
spec:
containers:
- image: morshemesh/unitydronesserver
name: drones-server
ports:
- containerPort: 5701
protocol: UDP
name: udp-port
23 changes: 23 additions & 0 deletions k8s/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /bin/sh
# https://docs.microsoft.com/en-us/azure/container-service/kubernetes/container-service-kubernetes-windows-walkthrough

# Creat Resource Group
az group create --name morshe-k8s-drones --location westeurope

# Create Cluster
az acs create --orchestrator-type kubernetes --resource-group morshe-k8s-drones --name morshe-k8s-drones --service-principal 4856f1fc-6060-4916-a541-47cf138c1bbb --client-secret /vUcloiV+xABtlSLhD28G7vW4U4dWuPQEXIPDD3d/jA= --generate-ssh-keys --agent-count 1 --master-count 1 --orchestrator-version 1.7

# Must for first time only ; Install Kubectl CLI. If you are using Windows than kubectl is in program files (x86). Make sure it is in your PATH variable
az acs kubernetes install-cli

# Connect kubectl to cluster
az acs kubernetes get-credentials --resource-group=morshe-k8s-drones --name=morshe-k8s-drones

# Proxy to the dashboard
kubectl proxy

# OR:::
kubectl get pods --all-namespaces
# copy *dashboard* name
kubectl port-forward kubernetes-dashboard-N-A-M-E-X-X-X 9090 --namespace kube-system
# browse http://localhost:9090/
1 change: 1 addition & 0 deletions paddle-soccer
Submodule paddle-soccer added at f61ac9

0 comments on commit 43f37f6

Please sign in to comment.