Create nginx controller with GKE

Prerequisites

  • Cluster already built.
  • Use kubectl.
  • Chat can be placed with helm install.
  • Cloud authenticated.
  • Use the default namespace of Kubernetes.
  • Tls has been created. (It works even without tls)

1. Push sample app to 'gcr'.

$ docker push newsdict/rust:v0.0.1
$ docker tag newsdict/rust:v0.0.1 docker gcr.io/newsdict-217812/docker_rust:v0.0.1
$ docker push gcr.io/newsdict-217812/docker_rust:v0.0.1

2. Place pod and service

Use kubectl to create service and pod. (It is written in one file, but it is okay to divide it.)

sample-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: docker-rust-service
  labels:
    name: docker-rust-service
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 3000
  selector:
    app: docker-rust
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: docker-rust
spec:
  replicas: 1
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: docker-rust
  template:
    metadata:
      labels:
        app: docker-rust
    spec:
      containers:
      - name: master
        image: gcr.io/newsdict-217812/docker_rust:v0.0.1
        workingDir: /rust
        resources:
          requests:
            cpu: 50m
            memory: 50Mi
        ports:
        - containerPort: 3000
        readinessProbe:
          httpGet:
            path: /
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5

Configuration

$ kubectl apply -f sample-service.yaml

3. Install nginx-ingress with helm

Create static ip

gcloud compute addresses create docker-rust-static-ip

install

$ helm install --name nginx-ingress stable/nginx-ingress --set rbac.create=true --set controller.service.loadBalancerIP=xxx.xxx.xxx.xxx
  • Replace xxx.xxx.xxx.xxx with your static-ip
  • --set rbac.create=true is an option only when using rbac.

Confirmation

Make sure that the creation is complete.

$ kubectl get service nginx-ingress
$ kubectl get pods |grep nginx

4. Place ingress

ingress.yml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: docker-rust-ingress
  annotations:
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
    - host: example-rust.newsdict.io
      http:
        paths:
          - backend:
              serviceName: docker-rust-service
              servicePort: 3000
            path: /
  tls:
    - hosts:
        - example-rust.newsdict.io
      secretName: docker-rust-tls

Apply

$ kubectl apply -f ingress.yml

5. Check ip

In nginx-ingress, IP that can be seen by $ kubectl get ingress can not be used, it is necessary to use IP of LoadBalancer located in service.

$ kubectl get service | grep nginx-ingress-controller

If EXTERNAL-IP displayed above is linked to DNS, etc., the introduction of nginx-ingress is complete

コメントを残す

メールアドレスが公開されることはありません。