[쿠버네티스 네트워크] 노드포트, 로드밸런서 연습문제

hi·2023년 7월 26일
0

쿠버네티스

목록 보기
37/64
post-custom-banner

연습문제

  • tomcat을 노드포트로 서비스하기(30003번 포트 사용)
  • tomcat을 로드밸런스로 서비스하기(80번 포트 사용)


kubectl create deploy tomcat --image=tomcat --dry-run=client -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: tomcat
  name: tomcat
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: tomcat
    spec:
      containers:
      - image: tomcat
        name: tomcat
        resources: {}
status: {}
kubectl create deploy tomcat --image=tomcat --dry-run=client -o yaml > tomcat-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: tomcat
  name: tomcat
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: tomcat
    spec:
      containers:
      - image: tomcat
        name: tomcat
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-svc-np
spec:
  type: NodePort
  selector:
    app.kubernetes.io/name: tomcat
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
      nodePort: 30002
---
apiVersion: v1
kind: Service
metadata:
  name: tomcat-svc-lb
spec:
  type: LoadBalancer
  selector:
    app.kubernetes.io/name: tomcat
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8080
kubectl create -f tomcat-deploy.yaml
kubectl get pods -w
imkunyoung@cloudshell:~/kubeservice (k8s-inflearn)$ kubectl get svc
NAME            TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)        AGE
kubernetes      ClusterIP      10.108.0.1     <none>          443/TCP        91m
tomcat-svc-lb   LoadBalancer   10.108.7.0     34.136.79.145   80:31998/TCP   40s
tomcat-svc-np   NodePort       10.108.10.39   <none>          80:30002/TCP   40s


gcloud compute firewall-rules create tomcat-svc-rule --allow=tcp:30002
kubectl get nodes -o wide
gunny_tangtang@cloudshell:~/kubeservice (k8s-inflearn)$ kubectl get nodes -o wide
NAME                                                STATUS   ROLES    AGE     VERSION           INTERNAL-IP   EXTERNAL-IP     OS-IMAGE             KERNEL-VERSION    CONTAINER-RUNTIME
gke-my-first-cluster-1-default-pool-a0f2cf43-ayqc   Ready    <none>   3d23h   v1.27.3-gke.100   10.128.0.7    34.69.195.120   Ubuntu 22.04.2 LTS   5.15.0-1036-gke   containerd://1.7.0
gke-my-first-cluster-1-default-pool-a0f2cf43-njrp   Ready    <none>   3d23h   v1.27.3-gke.100   10.128.0.8    35.232.215.24   Ubuntu 22.04.2 LTS   5.15.0-1036-gke   containerd://1.7.0
gke-my-first-cluster-1-default-pool-a0f2cf43-uu79   Ready    <none>   3d23h   v1.27.3-gke.100   10.128.0.9    35.202.160.16   Ubuntu 22.04.2 LTS   5.15.0-1036-gke   containerd://1.7.0

post-custom-banner

0개의 댓글