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

Split EKS commands and outputs for better copy and paste #841

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Changes from 1 commit
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
74 changes: 64 additions & 10 deletions content/en/user-guide/aws/elastic-kubernetes-service/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,27 @@ You can use the `docker` CLI to check that some containers have been created:

{{< command >}}
$ docker ps
{{< / command >}}

You can see an output similar to the following:

```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
...
b335f7f089e4 rancher/k3d-proxy:5.0.1-rc.1 "/bin/sh -c nginx-pr…" 1 minute ago Up 1 minute 0.0.0.0:8081->80/tcp, 0.0.0.0:44959->6443/tcp k3d-cluster1-serverlb
f05770ec8523 rancher/k3s:v1.21.5-k3s2 "/bin/k3s server --t…" 1 minute ago Up 1 minute
...
{{</ command >}}
```

After successfully creating and initializing the cluster, we can easily find the server endpoint, using the [`DescribeCluster`](https://docs.aws.amazon.com/eks/latest/APIReference/API_DescribeCluster.html) API. Run the following command:

{{< command >}}
$ awslocal eks describe-cluster --name cluster1
{{< / command >}}

You should get a response similar to the following:

```json
{
"cluster": {
"name": "cluster1",
Expand All @@ -88,7 +98,7 @@ $ awslocal eks describe-cluster --name cluster1
"clientRequestToken": "d188f578-b353-416b-b309-5d8c76ecc4e2"
}
}
{{</ command >}}
```

### Utilizing ECR Images within EKS

Expand Down Expand Up @@ -116,6 +126,11 @@ You can create a new ECR repository using the [`CreateRepository`](https://docs.

{{< command >}}
$ awslocal ecr create-repository --repository-name "fancier-nginx"
{{< / command >}}

You should get a response similar to the following:

```json
{
"repository": {
"repositoryArn": "arn:aws:ecr:us-east-1:000000000000:repository/fancier-nginx",
Expand All @@ -132,7 +147,7 @@ $ awslocal ecr create-repository --repository-name "fancier-nginx"
}
}
}
{{< / command >}}
```

{{< alert title="Note">}}
When creating an ECR repository, a port from the [external service port range]({{< ref "external-ports" >}}) is dynamically assigned. As a result, the port can differ from the static value `4510` used in the examples below.
Expand Down Expand Up @@ -163,13 +178,19 @@ Now, let us set up the EKS cluster using the image pushed to local ECR.
Next, we can configure `kubectl` to use the EKS cluster, using the [`UpdateKubeconfig`](https://docs.aws.amazon.com/eks/latest/APIReference/API_UpdateClusterConfig.html) API. Run the following command:

{{< command >}}
$ awslocal eks update-kubeconfig --name cluster1
& kubectl config use-context arn:aws:eks:us-east-1:000000000000:cluster/cluster1
$ awslocal eks update-kubeconfig --name cluster1 && \
kubectl config use-context arn:aws:eks:us-east-1:000000000000:cluster/cluster1
{{< / command >}}


You can see an output similar to the following:

```
...
Added new context arn:aws:eks:us-east-1:000000000000:cluster/cluster1 to /home/localstack/.kube/config
Switched to context "arn:aws:eks:us-east-1:000000000000:cluster/cluster1".
...
{{< / command >}}
```

You can now go ahead and add a deployment configuration for the `fancier-nginx` image.

Expand Down Expand Up @@ -262,11 +283,16 @@ You will be able to send a request to `nginx` via the load balancer port `8081`

{{< command >}}
$ curl http://localhost:8081/test123
{{< / command >}}

You should get a successful response with content similar to:

```html
<html>
...
<hr><center>nginx/1.21.6</center>
...
{{< / command >}}
```

{{< alert title="Note" >}}
You can customize the Load Balancer port by configuring `EKS_LOADBALANCER_PORT` in your environment.
Expand Down Expand Up @@ -320,6 +346,11 @@ You can create an EKS Cluster configuration using the following command:

{{< command >}}
$ awslocal eks create-cluster --name cluster1 --role-arn arn:aws:iam::000000000000:role/eks-role --resources-vpc-config '{}'
{{< / command >}}

You should get a response similar to the following:

```json
{
"cluster": {
"name": "cluster1",
Expand All @@ -330,13 +361,21 @@ $ awslocal eks create-cluster --name cluster1 --role-arn arn:aws:iam::0000000000
...
}
}
```

{{< command >}}
$ awslocal eks list-clusters
{{< / command >}}

You should get a response similar to the following:

```json
{
"clusters": [
"cluster1"
]
}
{{< / command >}}
```

To interact with your Kubernetes cluster, configure your Kubernetes client (such as `kubectl` or other SDKs) to point to the `endpoint` provided in the `create-cluster` output mentioned earlier. However, depending on whether you're calling the Kubernetes API from your local machine or from within a Lambda function, you might need to use different endpoint URLs.

Expand Down Expand Up @@ -406,11 +445,21 @@ This approach enables us to access the two distinct services using the same path

{{< command >}}
$ curl http://eks-service-1.localhost.localstack.cloud:8081/v1
{{< /command >}}

```
... [output of service 1]
```

{{< command >}}
$ curl http://eks-service-2.localhost.localstack.cloud:8081/v1
... [output of service 2]
{{< /command >}}

```
... [output of service 2]
```


It is important to note that the host names `eks-service-1.localhost.localstack.cloud` and `eks-service-2.localhost.localstack.cloud` both resolve to `127.0.0.1` (localhost). Consequently, you can utilize them to communicate with your service endpoints and distinguish between different services within the Kubernetes load balancer.

However, it might encounter issues in scenarios where you intend to run your Load Balancer (LB) on standard ports such as 80/443 since some of these ports may already be occupied on your local machine. For instance, by default, LocalStack allocates port 443 to expose APIs via the HTTPS endpoint (`https://localhost.localstack.cloud`). Hence, it's crucial to ensure that you expose your LB on a custom, non-standard port to prevent conflicts.
Expand All @@ -431,6 +480,11 @@ $ awslocal eks create-cluster \
--role-arn arn:aws:iam::000000000000:role/eks-role \
--resources-vpc-config '{}' \
--tags '{"_volume_mount_":"/path/on/host:/path/on/node"}'
{{< / command >}}

You should get a response similar to the following:

```json
{
"cluster": {
"name": "cluster1",
Expand All @@ -444,7 +498,7 @@ $ awslocal eks create-cluster \
...
}
}
{{< / command >}}
```

{{< alert title="Notes" >}}
Note that the tag was previously referred to as `__k3d_volume_mount__`, but it has now been renamed to `_volume_mount_`. As a result, the tag name `__k3d_volume_mount__` is considered deprecated and will be removed in an upcoming release.
Expand Down