Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Controller Example Page on Agones Website #3725

Merged
merged 19 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/custom-controller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Custom Controller for Agones Game Servers

Custom Controller is an example of how to deploy a controller that fits your needs. This
Custom Controller example helps manage game servers more easily by tracking and
logging detailed information whenever they are created, updated, or removed. This improves
your ability to see and control the servers without needing deep technical knowledge.
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

For detailed instructions refer to the [Agones Documentation](https://agones.dev/site/docs/examples/custom-controller/).
109 changes: 109 additions & 0 deletions site/content/en/docs/Examples/custom-controller.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: "Custom Controller for Agones Game Servers"
linkTitle: "Custom Controller"
date:
publishDate:
description: >
This Custom Controller example shows how to create, deploy and run a Custom Kubernetes Controller for Agones that logs changes to GameServers and modifies their labels.
---

markmandel marked this conversation as resolved.
Show resolved Hide resolved
## Prerequisite

To get started, ensure the following prerequisites are met:

- You have a running Kubernetes cluster.

- Agones is installed on your cluster. See [Agones guide](https://agones.dev/site/docs/installation/install-agones/).

- Example custom controller code is available {{< ghlink href="examples/custom-controller" >}}here{{< /ghlink >}}
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

## Deploy the Custom Controller

For a quick deployment of the custom controller on your cluster, execute:

```bash
kubectl apply -f deployment.yaml
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved
```

When you run this command, it quickly sets up your controller by doing four things:
- Creating a service account for secure communication with Kubernetes
- Defining a role with the right permissions to handle game servers and events
- Linking this role to the account for broad access
- Launching two controllers for reliability.
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

## Verify the Controller

To ensure the custom controller is operational, execute the following command. You should see two instances of the controller actively running:
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

```bash
kubectl get pods -n agones-system
```
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

## Monitor the log events for the custom controller pod

To monitor the log events of the custom controller pod during the creation, modification, and deletion of game servers, use the following command:

```bash
kubectl logs -f <custom-controller-pod> -n agones-system
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved
```

**Note**: If a custom controller runs into trouble with logging events, the backup controller will automatically assume the leadership role, ensuring uninterrupted logging of event details.
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

## Deploy the Agones Fleet
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

To apply the fleet configuration to your cluster, use the following command:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can lift the create a fleet markdown from https://agones.dev/site/docs/getting-started/create-fleet/#1-create-a-fleet

Then they don't need to worry about cloning the whole repository.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, I've copied the information from the create a fleet section. Would it be sufficient to include the link https://agones.dev/site/docs/getting-started/create-fleet/#1-create-a-fleet is enough?

something like:

## Create a Fleet

Please refer to the documentation on creating a fleet available at [this link](https://agones.dev/site/docs/getting-started/create-fleet/#1-create-a-fleet) for detailed information


```bash
kubectl apply -f examples/simple-game-server/fleet.yaml
```

When you run this command, it will:
- Specify that there should be 2 replicas of the Fleet.
- Specify that the Pods should have a container port named "default" with a value of 7654.
- Set the resource requests and limits for the container named `simple-game-server`.

## Create a GameServer Instance
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved

Create a gameserver using below command. After this, you'll be able to see logs about the server being created.

```bash
kubectl create -f <your-gameserver.yaml>
```

## Edit the GameServer

To edit settings of your game server, use:

```bash
kubectl edit gameserver <simple-game-server-name>
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved
```

This will open an editor for you to make changes, and the modification will be reflected in log events.

## Delete the GameServer

To remove your game server and track its deletion in the log events, run the following command:

```bash
kubectl delete gameserver <simple-game-server-name>
```

## Cleaning Up

When you're done with the Agones fleet and the custom controller, it's a good practice to clean up the resources to prevent unnecessary resource consumption. Follow these steps to remove them:

### Remove the Fleet

To delete the Agones fleet you deployed, execute the following command. This will remove the fleet along with all the game server instances it manages:

```bash
kubectl delete -f examples/simple-game-server/fleet.yaml
Kalaiselvi84 marked this conversation as resolved.
Show resolved Hide resolved
```

### Remove the Custom Controller

To remove the custom controller from your cluster, execute the following command. This will delete the deployment that you created earlier.

```bash
kubectl delete -f deployment.yaml
```
Loading