K8s 레시피 – ipify

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:January 17, 2022

ipify.org

ipify – A Simple Public IP Address API는 나의 IP 주소를 알고 싶을 때 이용한다. 웹브라우저로 접속하거나 curl 같은 명령줄 유틸리티로 API를 호출하면 된다. 이런 서비스는 참 많다. 그래도 ipify 만큼 깔끔한 곳이 많진 않아서 애용한다.

평소라면 이 서비스를 이용하면 되는데 간혹 자체 운영할 필요가 생긴다. 예를 들어 AWS에서 바라보는 나의 IP 주소가 ipify 등에서 바라보는 주소와 다를 때가 있다. 망이 얽히고 얽히는 해외망의 경우 이런 일이 잦다. 그러다 보니 ipify로 확인한 내 IP 주소를 방화벽에 넣었는데 이상하게 접속이 안 된다던가 하는 일이 발생한다. 이런 삽질을 줄이기 위해서 ipify 같은 서비스를 자체 운영한다.

ipify 같은 구현체는 GitHub에 많은데 여기서는 rdegges/ipify-api: A public IP API service를 이용하기로 한다. 공식 Docker 이미지를 제공하지 않기 때문에 내가 직접 만든 unchartedsky/ipify-api를 이용한다.

준비물

레시피

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ipify-api-ingress
  namespace: playground
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/backend-protocol: http
    nginx.ingress.kubernetes.io/proxy-body-size: 128m
spec:
  rules:
    - host: ipify.demo.com
      http:
        paths:
          - path: /
            backend:
              serviceName: ipify-api
              servicePort: 3000
---
apiVersion: v1
kind: Service
metadata:
  name: ipify-api
  namespace: playground
  labels:
    app: ipify-api
spec:
  selector:
    app: ipify-api
  ports:
    - port: 3000
      targetPort: 3000
      protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ipify-api
  namespace: playground
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ipify-api
  template:
    metadata:
      labels:
        app: ipify-api
    spec:
      containers:
        - name: ipify-api
          image: unchartedsky/ipify-api
          imagePullPolicy: IfNotPresent
          securityContext:
            runAsNonRoot: true
            runAsUser: 1000
          resources:
            requests:
              cpu: "50m"
              memory: "32Mi"
            limits:
              cpu: "500m"
              memory: "128Mi"
          ports:
            - name: ipify-api-port
              containerPort: 3000
          livenessProbe:
            httpGet:
              path: /
              port: ipify-api-port
            initialDelaySeconds: 60
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: ipify-api-port
            initialDelaySeconds: 60
            timeoutSeconds: 10

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments