자격증/CKA
[CKA] Deployment & Expose the Service
후드리챱챱
2023. 3. 26. 13:46
반응형
[문제]
* 작업 클러스터 : kubectl config use-context kubernetes-admin@kubernetes
Reconfigure the existing deployment front-end and add a port specification named http exposing port 80/tcp of the existing container nginx.
Create a new service named front-end-svc exposing the container port http
Configure the new service to also expose the individual Pods visa a NodePort on the nodes on which they are scheduled
[풀이]
# kubectl get deployments.apps front-end
# kubectl get deployments.apps front-end -o yaml > front-end.yaml
# cat front-end.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: front-end
spec:
replicas: 2
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx
name: http
ports:
- containerPort: 80
name: http
---
apiVersion: v1
kind: Service
metadata:
name: front-end-svc
spec:
type: NodePort
selector:
run: nginx
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
# kubectl delete deployment.apps front-end
# kubectl apply -f front-end.yaml
# kubectl get deployments.apps front-end
NAME READY UP-TO-DATE AVAILABLE AGE
front-end 2/2 2 2 29s
# kubectl get svc front-end-svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
front-end-svc NodePort 10.96.119.45 <none> 80:31380/TCP 7m1s
# curl node1.example.com:31380
<!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>
※ Service 관련 Docs 참고
https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
Service
Expose an application running in your cluster behind a single outward-facing endpoint, even when the workload is split across multiple backends.
kubernetes.io
[참고]
- 유투브 따배씨
반응형