Kubernetes has become the standard for container orchestration, enabling developers and DevOps teams to manage containerized applications efficiently and securely. It has a vibrant ecosystem and a vast community that continues to drive innovation and adoption of cloud-native technologies.
In kubernetes series article, we will explore Kubernetes' essential features, its role in managing containerized workloads, and its extensibility options, empowering developers to harness its full potential.
-
An Introduction to Kubernetes (3) Publish Application to Amazon Elastic Kubernetes Service
-
An Introduction to Kubernetes (4) Troubleshooting & References
Before we introduction the environment preparation and cluster. Here will introduction the key concepts in kubernetes:
- Pods: The smallest deployable units in Kubernetes, representing one or more containers.
- Services: An abstraction that provides stable network endpoints to access a set of pods.
- ReplicaSets: Ensures a specified number of identical pods are running at all times.
- Deployments: A higher-level abstraction for managing rolling updates and rollbacks of application replicas.
- Namespaces: A virtual cluster within a physical cluster that allows resource segregation and isolation.
Interact with EKS cluster
Setting your work instanances interact with EKS cluster:
aws eks update-kubeconfig --region $AWS_REGION --name $EKS_CLUSTER_NAME
checkout the config
cat ~/.kube/config
Test
kubectl get svc
Create namespaces
create namespaces for kubernetes arrange the resources.
$ kubectl create namespace eks-sample-app
namespace/eks-sample-app created
Deploy Application
Deploy an eks-sample-app to EKS cluster
Save fellowing to eks-sample-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-sample-linux-deployment
namespace: eks-sample-app
labels:
app: eks-sample-linux-app
# setting the replicaset rule
spec:
replicas: 3
selector:
matchLabels:
app: eks-sample-linux-app
# pod template
template:
metadata:
labels:
app: eks-sample-linux-app
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values:
- amd64
- arm64
containers:
- name: nginx
image: public.ecr.aws/nginx/nginx:1.23
ports:
- name: http
containerPort: 80
imagePullPolicy: IfNotPresent
nodeSelector:
kubernetes.io/os: linux
Deploy application
kubectl apply -f eks-sample-deployment.yaml
Create service
Create service naming, and other services can interaction by naming (also IP).
Here we create a service yaml, and in spec.type as LoadBalancer
(The Service “eks-sample-linux-service” is invalid: spec.type: Unsupported value: “LoadBalanceer”: supported values: “ClusterIP”, “ExternalName”, “LoadBalancer”, “NodePort”)
eks-sample-service.yaml
apiVersion: v1
kind: Service
metadata:
name: eks-sample-linux-service
namespace: eks-sample-app
labels:
app: eks-sample-linux-app
spec:
type: LoadBalancer
selector:
app: eks-sample-linux-app
ports:
- protocol: TCP
port: 80
targetPort: 80
Apply service to cluster
kubectl apply -f eks-sample-service.yaml
If you have change the cluster.yaml, can execute the upgrade command
eksctl upgrade cluster -f cluster.yaml
Preview your Resources in Cluster
List all resource in cluster by namespace
kubectl get all -n eks-sample-app
When list cluster resource, will list the service info, we can access the service by EXTERNAL-IP
curl {EXTERNAL-IP}