AWS EKS
AWS EKS
EKS Overview
- Service managed by Amazon that allows us to run Kubernetes on AWS, without having to manage the infra
Create a cluster
eksctl create cluster \
--name my-cluster \
--region region-name \
--fargate
...
[✓] EKS cluster "my-cluster" in "region-name" region is ready
Above line tells the cluster is ready to use in the given region
- After successful creation of cluster, in
~/.kube/config
we can see cluster details, like below
- name: chiras@cisco.com@chiras-eks-cluster1.ap-south-1.eksctl.io
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1
args:
- token
- -i
- chiras-eks-cluster1
command: aws-iam-authenticator
env:
- name: AWS_STS_REGIONAL_ENDPOINTS
value: regional
- name: AWS_DEFAULT_REGION
value: ap-south-1
- View your cluster nodes
kubectl get nodes -o wide
- View workloads on the cluster
kubectl get pods --all-namespaces -o wide
Deploy a sample application
- Create a namespace
kubectl create namespace <my-namespace>
- Create a K8s Service and Deployment using a YAML file
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: my-namespace
labels:
app: my-app
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
namespace: my-namespace
labels:
app: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: beta.kubernetes.io/arch
operator: In
values:
- amd64
- arm64
containers:
- name: nginx
image: public.ecr.aws/z9d2n7e1/nginx:1.19.5
ports:
- containerPort: 80
- Deploy the application
kubectl apply -f <sample-service.yaml>
- View the resources in the namespace
kubectl get all -n my-namespace