k8s nginx+php

工作負(fù)載

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-php
  labels:
    name: my-php
spec:
  replicas: 1
  selector:
    matchLabels:
      app: my-php
  template:
    metadata:
      labels:
        app: my-php
    spec:
      containers:
      - name: my-php
        image: php:7.2-fpm
        volumeMounts:
        - mountPath: /var/www/html/
          name: nginx-data
        ports:
        - containerPort: 9000
      volumes:
      - name: nginx-data
        hostPath:
         path: /root/k8s/html
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      app: my-nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx:1.8
        ports:
        - containerPort: 80
        volumeMounts:
        - name: nginx-data
          mountPath: /usr/share/nginx/html
        - name: nginx-conf
          mountPath: /etc/nginx/conf.d/
      volumes:
      - name: nginx-data
        hostPath:
         path: /root/k8s/html
      - name: nginx-conf
        hostPath:
         path: /root/k8s/conf

服務(wù)

apiVersion: v1
kind: Service
metadata:
  name: my-php
spec:
  ports:
  - name: my-php
    port: 9000
    protocol: TCP
    targetPort: 9000
  selector:
    app: my-php
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
spec:
  type: NodePort
  ports:
  - name: my-nginx
    port: 80
    protocol: TCP
    targetPort: 80
    nodePort: 30003
  selector:
    app: my-nginx

nginx配置 default.conf

server {
    listen       80;
    server_name  localhost;
 
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
 
    location / {
        root   /usr/share/nginx/html;#index.php文件位置 與php服務(wù)中/var/www/html同步
        index  index.html index.htm index.php;
    }
 
    #error_page  404              /404.html;
 
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
 
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #    root           html;
        #try_files $uri =404;
        fastcgi_pass   my-php:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
        include        fastcgi_params;
        set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
             set $real_script_name $1;
             set $path_info $2;
        }
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;

    }
 
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginx-example-ingess.yaml

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute # 類型為路由
metadata:
  name: example-nginx # 定義名稱
  namespace: default
spec:
  entryPoints:
    - web
  routes:
  - match: Host(`example.xxx.com`)  # 轉(zhuǎn)發(fā)到域名咖城,同時可以映射路徑 && PathPrefix(`/notls`)
    kind: Rule
    services:
    - name: my-nginx  # 前面創(chuàng)建的 service崭庸,要綁定對應(yīng)上
      port: 80
# 發(fā)布路由配置
kubectl apply -f nginx-example-ingess.yaml

修改 Host 為自己解析域名,新增nginx配置文件

cp default.conf nginxtest.conf 
#  server_name  example.xxx.com;

訪問
http://ip:30003
http://example.xxx.com

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末治宣,一起剝皮案震驚了整個濱河市急侥,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌侮邀,老刑警劉巖坏怪,帶你破解...
    沈念sama閱讀 218,525評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件绊茧,死亡現(xiàn)場離奇詭異,居然都是意外死亡华畏,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,203評論 3 395
  • 文/潘曉璐 我一進(jìn)店門侣夷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來仑乌,“玉大人百拓,你說我怎么就攤上這事绝骚§艄唬” “怎么了压汪?”我有些...
    開封第一講書人閱讀 164,862評論 0 354
  • 文/不壞的土叔 我叫張陵古瓤,是天一觀的道長腺阳。 經(jīng)常有香客問我穿香,道長,這世上最難降的妖魔是什么皮获? 我笑而不...
    開封第一講書人閱讀 58,728評論 1 294
  • 正文 為了忘掉前任,我火速辦了婚禮购公,結(jié)果婚禮上雁歌,老公的妹妹穿的比我還像新娘宏浩。我一直安慰自己靠瞎,他們只是感情好比庄,可當(dāng)我...
    茶點故事閱讀 67,743評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著乏盐,像睡著了一般佳窑。 火紅的嫁衣襯著肌膚如雪丑勤。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,590評論 1 305
  • 那天法竞,我揣著相機(jī)與錄音,去河邊找鬼薛躬。 笑死呆细,一個胖子當(dāng)著我的面吹牛型宝,可吹牛的內(nèi)容都是我干的絮爷。 我是一名探鬼主播,決...
    沈念sama閱讀 40,330評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼岖寞,長吁一口氣:“原來是場噩夢啊……” “哼柜蜈!你這毒婦竟也來了仗谆?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,244評論 0 276
  • 序言:老撾萬榮一對情侶失蹤藻雪,失蹤者是張志新(化名)和其女友劉穎狸吞,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體捷绒,經(jīng)...
    沈念sama閱讀 45,693評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,885評論 3 336
  • 正文 我和宋清朗相戀三年椭住,在試婚紗的時候發(fā)現(xiàn)自己被綠了字逗。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,001評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡些举,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出户魏,到底是詐尸還是另有隱情挪挤,我是刑警寧澤叼丑,帶...
    沈念sama閱讀 35,723評論 5 346
  • 正文 年R本政府宣布鸠信,位于F島的核電站,受9級特大地震影響星立,放射性物質(zhì)發(fā)生泄漏葬凳。R本人自食惡果不足惜绰垂,卻給世界環(huán)境...
    茶點故事閱讀 41,343評論 3 330
  • 文/蒙蒙 一火焰、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧酱畅,春花似錦、人聲如沸纺酸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,919評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽佑附。三九已至,卻和暖如春音同,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背权均。 一陣腳步聲響...
    開封第一講書人閱讀 33,042評論 1 270
  • 我被黑心中介騙來泰國打工叽赊, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留恋沃,地道東北人必指。 一個月前我還...
    沈念sama閱讀 48,191評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像梅割,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子炮捧,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,955評論 2 355

推薦閱讀更多精彩內(nèi)容