logo

How to deploy your simple nginx service in AWS EKS.

You already have a Kubernetes Cluster running, or else you can read my article How to create your first AWS EKS cluster using eksctl and get up and running with Amazon EKS very quickly.

Published Dec 28, 2023
Introduction :
in this article demonstrate how you can get up and running with your first deployment into your Amazon EKS (Kubernetes) and how you can access this outside your cluster using the Amazon Elastic Load Balancer.
The only thing you need to know here should be how Kubernetes works and how you write your YAML files for Kubernetes, the rest will help you with this.
Start Creating your files deployment and service yaml. the deployment will contain our service, replicas, and so on or the service will be the part we use to link our Amazon Elastic Load Balancer into our Amazon EKS (Kubernetes) Cluster service.
Step 1: Create a Deployment
Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
  • vim deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world-pod
image: nginx:latest
ports:
- containerPort: 80
  • After execute commnd below output:
1
2
3
4
5
6
7
8
9
10
11
12
[root@ip-172-31-17-53 ~]# kubectl apply -f deployment.yaml
deployment.apps/hello-world created

[root@ip-172-31-17-53 ~]# kubectl get po -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-world-79cff76897-7ffcj 1/1 Running 0 7s
kube-system aws-node-gsv85 1/1 Running 0 3m40s
kube-system aws-node-qphwl 1/1 Running 0 3m35s
kube-system coredns-7975d6fb9b-kh6jk 1/1 Running 0 10m
kube-system coredns-7975d6fb9b-nx67r 1/1 Running 0 10m
kube-system kube-proxy-lf7vc 1/1 Running 0 3m35s
kube-system kube-proxy-m4dqc 1/1 Running 0 3m40s
Step 2: Create a service
Service is a method for exposing a network application that is running as one or more Pods in your cluster.
Each Pod gets its own IP address (Kubernetes expects network plugins to ensure this). For a given Deployment in your cluster, the set of Pods running in one moment in time could be different from the set of Pods running that application a moment later.
1
2
3
4
[root@ip-172-31-17-53 ~]# kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 11m
kube-system kube-dns ClusterIP 10.100.0.10 <none> 53/UDP,53/TCP 10m
The Service API, part of Kubernetes, is an abstraction to help you expose groups of Pods over a network. Each Service object defines a logical set of endpoints (usually these endpoints are Pods) along with a policy about how to make those pods accessible.
  • vim service.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: v1
kind: Service
metadata:
name: hello-world-service
spec:
selector:
app: hello-world
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
After execute commnd below output:
1
2
3
4
5
[root@ip-172-31-17-53 ~]# kubectl get svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default hello-world-service LoadBalancer 10.100.238.91 aee3f06d0501f4528a7b0bad2fa2f85f-625499864.us-east-1.elb.amazonaws.com 80:30616/TCP 4s
default kubernetes ClusterIP 10.100.0.1 <none> 443/TCP 13m
kube-system kube-dns ClusterIP 10.100.0.10 <none> 53/UDP,53/TCP 13m
Command line Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@ip-172-31-17-53 ~]# curl aee3f06d0501f4528a7b0bad2fa2f85f-625499864.us-east-1.elb.amazonaws.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
Browser Output:
Conclusion :
This solution helps you quickly install simple application and access cluster using the Amazon Elastic Load Balancer