apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: php-pinpoint-demo
  namespace: default
  labels:
    app: php-pinpoint-demo
spec:
  selector:
    matchLabels:
      app: php-pinpoint-demo
  serviceName: php-pinpoint-demo
  replicas: 1
  #minReadySeconds: 60     #滚动升级时60s后认为该pod就绪
  template:
    metadata:
      labels:
        app: php-pinpoint-demo
      annotations:
        #net.ipv4.tcp_syncookies=0 need kernel version 4.4 or newer
        security.alpha.kubernetes.io/sysctls: "net.ipv4.tcp_syncookies=0,net.ipv4.ip_local_port_range=10000 65535"
        #kernel version 4.15 needed
        security.alpha.kubernetes.io/unsafe-sysctls: "net.core.somaxconn=65535,net.ipv4.tcp_tw_reuse=1,net.ipv4.tcp_fin_timeout=30,net.ipv4.tcp_keepalive_intvl=4,net.ipv4.tcp_keepalive_probes=3,net.ipv4.tcp_keepalive_time=120,net.ipv4.tcp_max_syn_backlog=65535,net.ipv4.tcp_rfc1337=1,net.ipv4.tcp_slow_start_after_idle=0,net.ipv4.tcp_fack=1,net.ipv4.tcp_max_tw_buckets=262144,net.ipv4.tcp_fastopen=3,net.ipv4.icmp_ratelimit=100,net.ipv4.tcp_abort_on_overflow=1,net.ipv4.tcp_adv_win_scale=2,net.ipv4.tcp_retries2=8,net.ipv4.tcp_syn_retries=3,net.ipv4.tcp_synack_retries=2,net.unix.max_dgram_qlen=512,net.ipv4.tcp_fwmark_accept=1,net.ipv4.fwmark_reflect=1,net.ipv4.tcp_no_metrics_save=1,net.netfilter.nf_conntrack_helper=1,net.netfilter.nf_conntrack_max=1048576,net.netfilter.nf_conntrack_tcp_timeout_close_wait=60,net.netfilter.nf_conntrack_tcp_timeout_established=120,net.netfilter.nf_conntrack_tcp_timeout_fin_wait=30,net.netfilter.nf_conntrack_tcp_timeout_last_ack=30,net.netfilter.nf_conntrack_tcp_timeout_time_wait=60"
    spec:
      terminationGracePeriodSeconds: 60 ##k8s将会给应用发送SIGTERM信号，可以用来正确、优雅地关闭应用,默认为30秒
      #从私有仓库下载镜像
      #imagePullSecrets:
      #- name: registrykey-ali-ext
      containers:
      - name: php-pinpoint-demo
        image: slpcat/php-pinpoint-demo
        imagePullPolicy: Always
        livenessProbe: #kubernetes认为该pod是存活的,不存活则需要重启
          httpGet:
            path: /
            port: 80
            scheme: HTTP
          initialDelaySeconds: 60 # equals to the maximum startup time of the application + couple of seconds
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        readinessProbe: #kubernetes认为该pod是启动成功的
          httpGet:
            path: /
            port: 80
            scheme: HTTP
          initialDelaySeconds: 30 # equals to minimum startup time of the application
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        env:
        - name: USER
          value: "root"
        - name: PASSWD
          value: "password"
        - name: BIND_ADDRESS
          value: "false"
        #pinpoint-c-agent config
        - name: AGENT_ID
          value: "k8s-php"
        - name: AGENT_TYPE
          value: "PHP"
        - name: APP_NAME
          value: "php-demo"
        - name: COLLECTOR_IP
          value: "pinpoint-collector-headless"
        - name: COLLECTOR_TCP_PORT
          value: "9994"
        - name: COLLECTOR_STAT_PORT
          value: "9995"
        - name: COLLECTOR_SPAN_PORT
          value: "9996"
        - name: LOGLEVEL
          value: "INFO"
        - name: LOGFILE_ROOTPATH
          value: "\/tmp"
        - name: PLUGIN_ROOTDIR
          value: "\/app\/pinpoint_plugins"
        resources:
          # keep request = limit to keep this container in guaranteed class
          requests:
            cpu: 500m
            memory: 1Gi
          limits:
            cpu: 2000m
            memory: 4Gi
        ports:
          - name: web
            containerPort: 80
