Skip to content

Instantly share code, notes, and snippets.

@mosuke5
Last active May 12, 2019 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosuke5/75738227c81f09994a66f607a5545bf6 to your computer and use it in GitHub Desktop.
Save mosuke5/75738227c81f09994a66f607a5545bf6 to your computer and use it in GitHub Desktop.
alibaba cloud serverless kubernetes sample code

Nginx DeploymentとService(type: loadbalancer)を動作させるサンプル。

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-lb
spec:
  type: LoadBalancer
  ports:
    - name: "http-port"
      protocol: "TCP"
      port: 80
      targetPort: 80 # Vserver groupのtarget
  selector:
    app: nginx # 上のNignxアプリを指定する必要がある

少し応用的なパターン。 コンテナのログの収集をLogServiceにさせるのと、Ingressも利用してみるパターン。L7レイヤーの制御が可能になる、

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-log
          # Set application log output path 
          mountPath: /var/log/nginx
      - name: ilogtail
        image: registry.cn-hangzhou.aliyuncs.com/acs/ilogtail:0.13.4-eb42407
        env:
          - name: "ALIYUN_REGION_ID"
            value: "us-west-1"
          - name: "ALIYUN_LOGTAIL_USER_ID"
            value: "xxxxxxxx"
          - name: "ALIYUN_LOGTAIL_USER_DEFINED_ID"
            value: "xxxxxxxx"
        volumeMounts:
        - name: nginx-log
          # The root path here will be set to the logtail configuration
          mountPath: /ecilogs
          readOnly: true
      volumes:
      - name: nginx-log
        emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-lb
spec:
  type: LoadBalancer
  ports:
    - name: "http-port"
      protocol: "TCP"
      port: 80
      targetPort: 80 # Vserver groupのtarget
  selector:
    app: nginx # 上のNignxアプリを指定する必要がある
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx
  clusterIP: None
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress
spec:
  rules:
  # Configure Layer-7 domain name
  - host: foo.bar.com
    http:
      paths:
      # Configure context path
      - path: /
        backend:
          serviceName: nginx-svc
          servicePort: 80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment