Git Product home page Git Product logo

agonespod's Introduction

CircleCI NuGet License: MIT

hub

AgonesPod

Kubernetes Client to manipulate Agones.

todo

  • GetGameServersAsync: GameServers (GET)
  • AllocateGameServersAsync: Allocate GameServer (POST)

Spec: Agones Kubernetes API | Agones

install

nuget

dotnet add package AgonesPod

kubernetes

deploy.yaml

docker

Build and push Docker Image

docker_version=1.2.0
docker build -t agonespod:${docker_version} -f samples/AgonesPod.ConsoleSample/Dockerfile .
docker tag agonespod:${docker_version} guitarrapc/agonespod:${docker_version}
docker push guitarrapc/agonespod:${docker_version}

how to run

Apply Agones to your kubernetes cluster.

REF: https://agones.dev/site/docs/installation/#installing-agones

$ helm repo add agones https://agones.dev/chart/stable
$ helm upgrade --install --name agones --namespace agones-system agones/agones
$ helm delete agones

deploy Agones Fleet and agonespod to your cluster. let's use https://github.com/guitarrapc/agones-udp-server-csharp to wake up fleet.

git clone https://github.com/guitarrapc/agones-udp-server-csharp.git
kubectl apply -f ./agones-udp-server-csharp/k8s/
kubectl delete -f ./agones-udp-server-csharp/k8s/

Run agonespod on pod.

kubectl apply -f ./k8s/
pod=$(kubectl get pods -o json | jq -r .items[].metadata.name | grep agonespod | head -n 1)
kubectl exec -it $pod -- dotnet AgonesPod.ConsoleSample.dll getgameserver

You may get Agones GameServer info.

# GetGameServer
  Host:Port = 192.168.65.3:7969
    IsRunningOnKubernetes : True
    IsAllocated : False
    NameSpace : default
    Name : simple-udp-rcdvt-xr6vn
    Address : 192.168.65.3
    Port : 7969
    State : Ready
    Fleet : simple-udp
    SdkVersion : 1.2.0
  Host:Port = 192.168.65.3:7598
    IsRunningOnKubernetes : True
    IsAllocated : True
    NameSpace : default
    Name : simple-udp-rcdvt-zxpwl
    Address : 192.168.65.3
    Port : 7598
    State : Allocated
    Fleet : simple-udp
    SdkVersion : 1.2.0

Debug

publish on linux and cp to pod and run.

dotnet publish
pod=$(kubectl get pods -o json | jq -r .items[].metadata.name | grep agonespod | head -n 1)
kubectl cp ./samples/AgonesPod.ConsoleSample/bin/Debug/netcoreapp3.1/publish/AgonesPod.ConsoleSample.dll ${pod}:/app/AgonesPod.ConsoleSample.dll
kubectl cp ./samples/AgonesPod.ConsoleSample/bin/Debug/netcoreapp3.1/publish/AgonesPod.dll ${pod}:/app/AgonesPod.dll
kubectl exec -it ${pod} dotnet AgonesPod.ConsoleSample.dll getgameserver

sample usage

pod=$(kubectl get pods -o json | jq -r .items[].metadata.name | grep agonespod | head -n 1)
kubectl exec -it ${pod} -- dotnet AgonesPod.ConsoleSample.dll getgameserver
kubectl exec -it ${pod} -- dotnet AgonesPod.ConsoleSample.dll allocategameserver -f simple-udp

cURL

AgonesPod checking kubernetes API && Agones Controller behaviour with cURL.

Access Agones via the Kubernetes API | Agones

list agones resources

request

pod=$(kubectl get pods -o json | jq -r .items[].metadata.name | grep agonespod | head -n 1)
kubectl exec -it ${pod} /bin/bash
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -s -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://$KUBERNETES_SERVICE_HOST:443/apis -k | grep agones -A 3 -B 1

response

    {
      "name": "agones.dev",
      "versions": [
        {
          "groupVersion": "agones.dev/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "agones.dev/v1",
        "version": "v1"
      }
    },
    {
      "name": "allocation.agones.dev",
      "versions": [
        {
          "groupVersion": "allocation.agones.dev/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "allocation.agones.dev/v1",
        "version": "v1"
      }
    },
    {
      "name": "autoscaling.agones.dev",
      "versions": [
        {
          "groupVersion": "autoscaling.agones.dev/v1",
          "version": "v1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "autoscaling.agones.dev/v1",
        "version": "v1"
      }
    },
    {
      "name": "multicluster.agones.dev",
      "versions": [
        {
          "groupVersion": "multicluster.agones.dev/v1alpha1",
          "version": "v1alpha1"
        }
      ],
      "preferredVersion": {
        "groupVersion": "multicluster.agones.dev/v1alpha1",
        "version": "v1alpha1"
      }
    },

getgameserver

request

pod=$(kubectl get pods -o json | jq -r .items[].metadata.name | grep agonespod | head -n 1)
kubectl exec -it ${pod} /bin/bash
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -s -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" https://$KUBERNETES_SERVICE_HOST:443/apis/agones.dev/v1/namespaces/default/gameservers -k

response

{"apiVersion":"agones.dev/v1","items":[{"apiVersion":"agones.dev/v1","kind":"GameServer","metadata":{"annotations":{"agones.dev/ready-container-id":"docker://f6603880bfb885906780709d9d5ae8ec8b2a02ba591d12e76dc27ebc101e36e6","agones.dev/sdk-version":"1.2.0"},"creationTimestamp":"2019-12-27T08:43:36Z","finalizers":["agones.dev"],"generateName":"simple-udp-rcdvt-","generation":6,"labels":{"agones.dev/fleet":"simple-udp","agones.dev/gameserverset":"simple-udp-rcdvt"},"name":"simple-udp-rcdvt-xr6vn","namespace":"default","ownerReferences":[{"apiVersion":"agones.dev/v1","blockOwnerDeletion":true,"controller":true,"kind":"GameServerSet","name":"simple-udp-rcdvt","uid":"f89d85f7-2884-11ea-850e-00155d644a2b"}],"resourceVersion":"1184988","selfLink":"/apis/agones.dev/v1/namespaces/default/gameservers/simple-udp-rcdvt-xr6vn","uid":"f8bcf887-2884-11ea-850e-00155d644a2b"},"spec":{"container":"simple-udp","health":{"failureThreshold":3,"initialDelaySeconds":15,"periodSeconds":5},"ports":[{"containerPort":7654,"hostPort":7969,"name":"default","portPolicy":"Dynamic","protocol":"UDP"}],"scheduling":"Packed","sdkServer":{"grpcPort":9357,"httpPort":9358,"logLevel":"Info"},"template":{"metadata":{"creationTimestamp":null},"spec":{"containers":[{"args":["run"],"image":"guitarrapc/agones-udp-server-csharp:1.2.1","imagePullPolicy":"Always","name":"simple-udp","resources":{"limits":{"cpu":"20m","memory":"64Mi"},"requests":{"cpu":"20m","memory":"64Mi"}}}]}}},"status":{"address":"192.168.65.3","nodeName":"docker-desktop","ports":[{"name":"default","port":7969}],"reservedUntil":null,"state":"Ready"}},{"apiVersion":"agones.dev/v1","kind":"GameServer","metadata":{"annotations":{"agones.dev/ready-container-id":"docker://30127e97b7248eacfd82d64f1556dbe73c2291d81007a23d73a2298091519534","agones.dev/sdk-version":"1.2.0"},"creationTimestamp":"2019-12-27T08:47:57Z","finalizers":["agones.dev"],"generateName":"simple-udp-rcdvt-","generation":7,"labels":{"agones.dev/fleet":"simple-udp","agones.dev/gameserverset":"simple-udp-rcdvt"},"name":"simple-udp-rcdvt-zxpwl","namespace":"default","ownerReferences":[{"apiVersion":"agones.dev/v1","blockOwnerDeletion":true,"controller":true,"kind":"GameServerSet","name":"simple-udp-rcdvt","uid":"f89d85f7-2884-11ea-850e-00155d644a2b"}],"resourceVersion":"1185633","selfLink":"/apis/agones.dev/v1/namespaces/default/gameservers/simple-udp-rcdvt-zxpwl","uid":"94ad2ab3-2885-11ea-850e-00155d644a2b"},"spec":{"container":"simple-udp","health":{"failureThreshold":3,"initialDelaySeconds":15,"periodSeconds":5},"ports":[{"containerPort":7654,"hostPort":7598,"name":"default","portPolicy":"Dynamic","protocol":"UDP"}],"scheduling":"Packed","sdkServer":{"grpcPort":9357,"httpPort":9358,"logLevel":"Info"},"template":{"metadata":{"creationTimestamp":null},"spec":{"containers":[{"args":["run"],"image":"guitarrapc/agones-udp-server-csharp:1.2.1","imagePullPolicy":"Always","name":"simple-udp","resources":{"limits":{"cpu":"20m","memory":"64Mi"},"requests":{"cpu":"20m","memory":"64Mi"}}}]}}},"status":{"address":"192.168.65.3","nodeName":"docker-desktop","ports":[{"name":"default","port":7598}],"reservedUntil":null,"state":"Allocated"}}],"kind":"GameServerList","metadata":{"continue":"","resourceVersion":"1191374","selfLink":"/apis/agones.dev/v1/namespaces/default/gameservers"}}

allocate

request

kubectl exec -it agonespod /bin/bash
TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
curl -s -H "Authorization: Bearer $TOKEN" -d '{"apiVersion":"allocation.agones.dev/v1","kind":"GameServerAllocation","spec":{"required":{"matchLabels":{"agones.dev/fleet":"simple-udp"}}}}' -H "Content-Type: application/json" -X POST https://$KUBERNETES_SERVICE_HOST:443/apis/allocation.agones.dev/v1/namespaces/default/gameserverallocations -k

response

{"kind":"GameServerAllocation","apiVersion":"allocation.agones.dev/v1","metadata":{"name":"simple-udp-btdzt-fn65w","namespace":"default","creationTimestamp":"2019-10-28T06:20:08Z"},"spec":{"multiClusterSetting":{"policySelector":{}},"required":{"matchLabels":{"agones.dev/fleet":"simple-udp"}},"scheduling":"Packed","metadata":{}},"status":{"state":"Allocated","gameServerName":"simple-udp-btdzt-fn65w","ports":[{"name":"default","port":7934}],"address":"192.168.65.3","nodeName":"docker-desktop"}}

REF

Access Agones via the Kubernetes API | Agones

Agones Kubernetes API | Agones

Thank you to

Overview is follow to Pripod structure and bollow JsonCodes.

mayuki/Pripod: Pripod enables you to easily access Pod information from the .NET app inside a Pod.

agonespod's People

Contributors

guitarrapc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

agonespod's Issues

Failed to get gameserver. Response status code does not indicate success: 403 (Forbidden)

Please help to resolve :

Failed to get gameserver. Response status code does not indicate success: 403 (Forbidden). at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at System.Net.Http.HttpClient.GetByteArrayAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at AgonesPod.KubernetesServiceProviderBase.GetGameServers(HttpClient httpClient, String apiPath)
at AgonesPod.KubernetesServiceProviderBase.GetGameServersAsync()

On Calling : _agonesServiceProvider.GetGameServersAsync().GetAwaiter().GetResult();

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.