Kubernetes集群部署Nginx服务_kubesphere nginx

最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

资料预览

给大家整理的视频资料:

给大家整理的电子书资料:

如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

设置污点

#给node192.168.79.111 设置污点key为key值为nginx effec为NoSchedule永不调度
#除非在Pod里设置了对应的tolerations参数
kubectl taint node 192.168.79.111 key=nginx:NoSchedule

查看污点

[root@kmaster79110 promethues]# kubectl taint node 192.168.79.111 key=nginx:NoSchedule
node/192.168.79.111 tainted

[root@kmaster79110 promethues]# kubectl describe node 192.168.79.111
Name:               192.168.79.111
Roles:              <none>
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    dashboard=turnon
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=192.168.79.111
                    kubernetes.io/os=linux
                    type=nginx
Annotations:        node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Wed, 23 Jun 2021 15:11:03 +0800
Taints:             key=nginx:NoSchedule
Unschedulable:      false
Lease:
  HolderIdentity:  192.168.79.111
  AcquireTime:     <unset>
  RenewTime:       Thu, 24 Jun 2021 23:36:48 +0800
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Thu, 24 Jun 2021 23:34:21 +0800   Thu, 24 Jun 2021 07:15:55 +0800   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Thu, 24 Jun 2021 23:34:21 +0800   Thu, 24 Jun 2021 07:15:55 +0800   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Thu, 24 Jun 2021 23:34:21 +0800   Thu, 24 Jun 2021 07:15:55 +0800   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Thu, 24 Jun 2021 23:34:21 +0800   Thu, 24 Jun 2021 07:15:55 +0800   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.79.111
  Hostname:    192.168.79.111
Capacity:
  cpu:                1
  ephemeral-storage:  103757316Ki
  hugepages-2Mi:      0
  memory:             4015196Ki
  pods:               210
Allocatable:
  cpu:                1
  ephemeral-storage:  95622742268
  hugepages-2Mi:      0
  memory:             3912796Ki
  pods:               210
System Info:
  Machine ID:                 4a78154c965a40aab1a1693fb8a32f46
  System UUID:                b2a04d56-33a5-145f-4eae-af3b16123147
  Boot ID:                    dd6b58d2-cb34-4415-af1e-49fc8ac515c9
  Kernel Version:             4.19.12-1.el7.elrepo.x86_64
  OS Image:                   CentOS Linux 7 (Core)
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://19.3.13
  Kubelet Version:            v1.21.0
  Kube-Proxy Version:         v1.21.0
PodCIDR:                      172.30.0.0/25
PodCIDRs:                     172.30.0.0/25
Non-terminated Pods:          (3 in total)
  Namespace                   Name                                CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                                ------------  ----------  ---------------  -------------  ---
  kube-system                 coredns-5969657997-fzmph            100m (10%)    0 (0%)      70Mi (1%)        170Mi (4%)     32h
  kube-system                 metrics-server-794dfd4bbb-w5lpc     0 (0%)        0 (0%)      0 (0%)           0 (0%)         32h
  kube-system                 traefik-ingress-controller-hx5zm    0 (0%)        0 (0%)      0 (0%)           0 (0%)         32h
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                100m (10%)  0 (0%)
  memory             70Mi (1%)   170Mi (4%)
  ephemeral-storage  0 (0%)      0 (0%)
  hugepages-2Mi      0 (0%)      0 (0%)
Events:              <none>

二.设置Nginx-deployment的yaml文件

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: nginx
      #标签选择器
      nodeSelector:
        type: nginx
      #设置污点可以调度到对应服务器
      tolerations:
      - key: "key"
        operator: "Equal"
        value: "nginx"
        effect: "NoSchedule"

应用启动

kubectl apply -f nginx-deployment.yaml

查看已经调度到对应的服务器

# kubectl get pod -o wide
NAME                                    READY   STATUS    RESTARTS   AGE     IP            NODE            NOMINATED NODE   READINESS GATES
nginx-deployment-57f94c46b4-5whb5       1/1     Running   0          6h30m   172.17.97.3   192.168.1.232   <none>           <none>

三.设置Nginx配置文件和程序根目录挂载

启动的Nginx使用默认的配置文件和默认的网站根目录,需要使用volume挂载

# cat nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx:latest
        name: nginx
        volumeMounts:
        - name: conf
          mountPath: /etc/nginx
        - name: opt
          mountPath: /opt
      #标签选择器
      nodeSelector:
        type: nginx
      #设置污点可以调度到对应服务器
      tolerations:
      - key: "key"
        operator: "Equal"
        value: "nginx"
        effect: "NoSchedule"
      volumes:
      - name: conf
        hostPath:
          path: /etc/nginx
          type: Directory
      - name: opt
        hostPath:
          path: /opt
          type: Directory

本次使用了本机挂载hostPath挂载配置文件及根目录,生产环境最好使用pvc挂载

四.设置Service对外提供服务

# cat nginx-service.yaml
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx-deployment
spec:
  ports:
  - port: 80
    name: nginx-svc8880
    protocol: TCP
    targetPort: 80
    nodePort: 8880  
  selector:
    app: nginx
  type: NodePort


PS:使用NodePort启用端口对外提供服务,如果对外映射多个端口需要在port参数下加参数name定义名称,单个端口无需设置参数name

k8s默认使用NodePort对外映射端口为30000-50000如需要映射其他端口需要修改配置文件/opt/kubernetes/cfg/kube-apiserver,修改端口范围
在这里插入图片描述

五、将博客模板导入导入容器

[root@kmaster79111 test]# docker cp 30f9301444d7:/etc/nginx .
[root@kmaster79111 test]# ll
total 0
drwxr-xr-x 5 root root 240 Jun 26 06:25 nginx
[root@kmaster79111 test]# cd nginx/
[root@kmaster79111 nginx]# ll moban5179
total 164
-rw-r--r-- 1 root root 11365 Jan 13 15:50 about.html
-rw-r--r-- 1 root root 21522 Jan 13 15:50 blog-details-fullwidth.html
-rw-r--r-- 1 root root 25133 Jan 13 15:50 blog-details.html
-rw-r--r-- 1 root root  8611 Jan 13 15:50 contact.html
drwxr-xr-x 4 root root    96 Oct 29  2020 css
drwxr-xr-x 7 root root  4096 Oct 29  2020 images
-rw-r--r-- 1 root root 21890 Jan 13 15:50 index-2.html
-rw-r--r-- 1 root root 27032 Jan 13 15:50 index-3.html
-rw-r--r-- 1 root root 27202 Jan 13 15:50 index.html
drwxr-xr-x 2 root root    89 Oct 29  2020 js
drwxr-xr-x 4 root root    31 Oct 29  2020 plugins
-rw-r--r-- 1 root root  3177 Nov 10  2016 ╦╡├ў.htm
[root@kmaster79111 nginx]# ll
total 7832
drwxr-xr-x 2 root root      26 Jun 26 06:31 conf.d
-rw-r--r-- 1 root root 1350222 Jun 25 21:49 Desktop.zip
-rw-r--r-- 1 root root    1007 May 25 20:28 fastcgi_params
drwxr-xr-x 2 root root    4096 Jun 25 21:48 Machine777_CSDN
-rw-r--r-- 1 root root  345563 Jun 25 21:48 Machine777_CSDN.html
-rw-r--r-- 1 root root    5290 May 25 20:28 mime.types
drwxr-xr-x 6 root root     235 Jan 13 15:59 moban5179
-rw-r--r-- 1 root root 6288470 Jun 25 22:25 moban5179.zip
lrwxrwxrwx 1 root root      22 May 25 21:01 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root     648 May 25 21:01 nginx.conf
-rw-r--r-- 1 root root     636 May 25 20:28 scgi_params
-rw-r--r-- 1 root root     664 May 25 20:28 uwsgi_params
[root@kmaster79111 nginx]# vim conf.d/default.conf 
[root@kmaster79111 nginx]# cat conf.d/default.conf 
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access\_log /var/log/nginx/host.access.log main;


![](https://img-blog.csdnimg.cn/img_convert/9a8cb5f8c0ec69e6499adead0da6e95b.png)


最全的Linux教程,Linux从入门到精通

======================

1.  **linux从入门到精通(第2版)**

2.  **Linux系统移植**

3.  **Linux驱动开发入门与实战**

4.  **LINUX 系统移植 第2版**

5.  **Linux开源网络全栈详解 从DPDK到OpenFlow**



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/59742364bb1338737fe2d315a9e2ec54.png)



第一份《Linux从入门到精通》466页

====================

内容简介

====

本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/9d4aefb6a92edea27b825e59aa1f2c54.png)



**本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**

> 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618635766)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

阅读,同时也非常适合准备从事Linux平台开发的各类人员。**

> 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/topics/618635766)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值