Added configs

This commit is contained in:
gabenov.s
2025-10-27 22:21:32 +03:00
parent 82744a8abb
commit a8ed29b600
7 changed files with 199 additions and 60 deletions

View File

@@ -0,0 +1,80 @@
# 1. Create a Deployment of nginx
kubectl create deployment my-nginx --image=nginx:latest --port=80
# 2. Expose the Deployment as a NodePort service
kubectl expose deployment my-nginx \
--type=NodePort \
--port=80 \
--target-port=80 \
--name=my-nginx-service
===============
# backend-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
spec:
replicas: 1
selector:
matchLabels:
app: backend
template:
metadata:
labels:
app: backend
spec:
containers:
- name: http-echo
image: hashicorp/http-echo:0.2.3
args:
- "-listen=:8080"
- "-text=Hello from the Backend!"
ports:
- containerPort: 8080
-------------
# backend-service.yaml
apiVersion: v1
kind: Service
metadata:
name: backend-service
spec:
type: ClusterIP # Default
selector:
app: backend
ports:
- port: 80 # Service port (used by internal clients)
targetPort: 8080 # Container port in the backend Pod
------------
# frontend-deployment.yaml
-------
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
spec:
replicas: 1
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: curl-loop
image: curlimages/curl:7.86.0
command: ["/bin/sh"]
args:
- "-c"
- |
while true; do
echo "=== Calling backend-service:80 ==="
curl -s backend-service:80
echo
sleep 5
done
-----------

View File

@@ -0,0 +1,119 @@
### **Prerequisites**
1. **AWS CLI Installed & Configured** (`aws configure`)
2. **kubectl Installed**
3. **A Running EKS Cluster** (Amazon Elastic Kubernetes Service)
4. **IAM Permissions** to create and manage EKS resources
---
### **Steps to Deploy Kubernetes Deployment to a LoadBalancer in AWS**
#### **Step 1: Create an EKS Cluster (If Not Already Running)**
```sh
aws eks create-cluster \
--name my-cluster \
--role-arn arn:aws:iam::123456789012:role/EKSClusterRole \
--resources-vpc-config subnetIds=subnet-xxxxxxxx,securityGroupIds=sg-xxxxxxxx
```
This step may take some time. You can verify the cluster status:
```sh
aws eks describe-cluster \
--name my-cluster \
--query "cluster.status"
```
#### **Step 2: Update `kubectl` to Use the New Cluster**
```sh
aws eks update-kubeconfig --name my-cluster
```
Ensure `kubectl` is using the correct context:
```sh
kubectl config current-context
```
#### **Step 3: Deploy an Application**
Create a simple deployment file (`deployment.yaml`):
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 2
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: nginx
ports:
- containerPort: 80
```
Apply the deployment:
```sh
kubectl apply -f deployment.yaml
```
#### **Step 4: Create a LoadBalancer Service**
Create a service file (`service.yaml`):
```yaml
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
type: LoadBalancer
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
```
Apply the service:
```sh
kubectl apply -f service.yaml
```
#### **Step 5: Get the LoadBalancer URL**
Once deployed, you can get the external IP using:
```sh
kubectl get svc my-app-service
```
The output will show something like:
```
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-app-service LoadBalancer 10.100.200.1 a1b2c3d4.amazonaws.com 80/TCP 5m
```
---
### **Verifying the Deployment**
Check if the pods are running:
```sh
kubectl get pods
```
Check logs:
```sh
kubectl logs -f <pod-name>
```
Access the application in your browser using the `EXTERNAL-IP`.
---
### **Cleanup**
To delete resources:
```sh
kubectl delete -f deployment.yaml
kubectl delete -f service.yaml
aws eks delete-cluster --name my-cluster
```