当前位置:   article > 正文

k8s上跑nacos

k8s上跑nacos

   nacos是阿里开源的一款动态服务发现、服务配置管理、服务及流量管理的应用。如果大家也在k8s里面用nacos请给我留言

公司一整套环境都是跑在容器平台上的,新接入nacos,容器化如下,在写这篇博客的时候阿里的nacos官方文档还没有k8s的教程

整体结构:

mysql做数据库,nginx代理后端nacos集群,clent端直接访问nginx,返回nacos集群的配置信息

1.nginx.yml

  1. ---
  2. kind: ConfigMap
  3. apiVersion: v1
  4. metadata:
  5. name: nginx-nacos
  6. labels:
  7. version: "1.0"
  8. data:
  9. ##################################### nginx #####################################
  10. nginx.conf: |-
  11. server {
  12. listen 80;
  13. charset utf-8;
  14. sendfile on;
  15. location / {
  16. rewrite '^/([a-z]+)/([a-z]+)$' /midenv/$1-$2.html;
  17. }
  18. location /midenv {
  19. root /usr/share/nginx/html;
  20. }
  21. }
  22. ---
  23. # ---
  24. # kind: ConfigMap
  25. # apiVersion: v1
  26. # metadata:
  27. # name: nginx-html
  28. # namespace: zf
  29. # labels:
  30. # version: "1.0"
  31. # data:
  32. # ##################################### nginx #####################################
  33. # nacos-serverlist.html: |-
  34. # nacos:8848
  35. # ---
  36. ---
  37. apiVersion: v1
  38. kind: Service
  39. metadata:
  40. name: nacos
  41. labels:
  42. version: "1.0"
  43. spec:
  44. ports:
  45. - port: 80
  46. protocol: TCP
  47. targetPort: 80
  48. selector:
  49. name: nacos
  50. version: "1.0"
  51. ---
  52. apiVersion: extensions/v1beta1
  53. kind: Ingress
  54. metadata:
  55. name: nacos-ingress
  56. spec:
  57. rules:
  58. - host: nacos.youdomain.com
  59. http:
  60. paths:
  61. - path: /
  62. backend:
  63. serviceName: nacosb
  64. servicePort: 80
  65. ---
  66. ---
  67. apiVersion: extensions/v1beta1
  68. kind: Deployment
  69. metadata:
  70. name: nacos
  71. labels:
  72. version: "1.0"
  73. spec:
  74. replicas: 1
  75. selector:
  76. matchExpressions:
  77. - {
  78. key: name, operator: In, values: [nacos],
  79. key: version, operator: In, values: ["1.0"]
  80. }
  81. template:
  82. metadata:
  83. labels:
  84. name: nacos
  85. version: "1.0"
  86. spec:
  87. volumes:
  88. - name: nginx-nacos
  89. configMap:
  90. name: nginx-nacos
  91. items:
  92. - key: nginx.conf
  93. path: nginx.conf
  94. # - name: aucpackage
  95. # nfs:
  96. # path: /data/template/html/aucpackage
  97. # server: nfs server
  98. containers:
  99. - name: nacosn
  100. image: nginx
  101. imagePullPolicy: IfNotPresent
  102. livenessProbe:
  103. tcpSocket:
  104. port: 80
  105. initialDelaySeconds: 10
  106. periodSeconds: 30
  107. ports:
  108. - containerPort: 80
  109. protocol: TCP
  110. volumeMounts:
  111. - mountPath: /etc/nginx/conf.d/
  112. name: nginx-nacos
  113. # volumeMounts:
  114. # - mountPath: /usr/share/nginx/html/midenv/
  115. # name: nginx-html

2.mysql.yml

  1. ---
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: mysql-youdomain-service
  6. labels:
  7. version: "1.0"
  8. spec:
  9. type: NodePort
  10. ports:
  11. - port: 3306
  12. protocol: TCP
  13. targetPort: 3306
  14. selector:
  15. name: mysql-chezhibao
  16. version: "1.0"
  17. ---
  18. apiVersion: extensions/v1beta1
  19. kind: Deployment
  20. metadata:
  21. name: mysql-youdomain
  22. labels:
  23. name: mysql-youdomain
  24. version: "1.0"
  25. spec:
  26. replicas: 1
  27. strategy:
  28. rollingUpdate:
  29. maxSurge: 1
  30. maxUnavailable: 1
  31. type: RollingUpdate
  32. template:
  33. metadata:
  34. labels:
  35. name: mysql-youdomain
  36. version: "1.0"
  37. spec:
  38. volumes:
  39. - name: sqldata
  40. nfs:
  41. path: /mysql/youdomain/data
  42. server: youNFS Service address
  43. ###这里放mysql的逻辑备份文件,注意文件格式是.sql的
  44. - name: sqldump
  45. nfs:
  46. path: /mysql/youdomain/docker-entrypoint-initdb.d/
  47. server: youNFS Service address
  48. ###这里是挂载mysql的配置文件
  49. - name: conf
  50. nfs:
  51. path: /mysql/conf
  52. server: youNFS Service address
  53. containers:
  54. - name: msql-youdomain
  55. image: mysql:5.7
  56. imagePullPolicy: IfNotPresent
  57. resources:
  58. requests:
  59. memory: 1Gi
  60. ports:
  61. - containerPort: 3306
  62. protocol: TCP
  63. env:
  64. - name: MYSQL_ROOT_PASSWORD
  65. value: "password"
  66. # - name: --lower-case-table-names
  67. # value: "1"
  68. volumeMounts:
  69. - name: sqldata
  70. mountPath: /var/lib/mysql/
  71. - name: sqldump
  72. mountPath: /docker-entrypoint-initdb.d/
  73. - name: conf
  74. mountPath: /etc/mysql/conf.d

3.nacos.yml

  1. ---
  2. apiVersion: v1
  3. kind: Service
  4. metadata:
  5. name: nacosserver
  6. labels:
  7. version: "1.0"
  8. spec:
  9. type: NodePort
  10. ports:
  11. - name: sver
  12. protocol: TCP
  13. port: 8848
  14. targetPort: 8848
  15. selector:
  16. name: nacosserver
  17. version: "1.0"
  18. ---
  19. apiVersion: extensions/v1beta1
  20. kind: Deployment
  21. metadata:
  22. name: nacosserver
  23. labels:
  24. version: "1.0"
  25. spec:
  26. replicas: 1
  27. strategy:
  28. rollingUpdate:
  29. maxSurge: 1
  30. maxUnavailable: 1
  31. type: RollingUpdate
  32. template:
  33. metadata:
  34. labels:
  35. name: nacosserver
  36. version: "1.0"
  37. spec:
  38. volumes:
  39. containers:
  40. - name: nacosserver
  41. image: nacos0.3
  42. imagePullPolicy: IfNotPresent
  43. resources:
  44. requests:
  45. memory: 1Gi
  46. ports:
  47. - containerPort: 8848
  48. name: web
  49. protocol: TCP

4.nacos的dockerfile

  1. # Version 0.1
  2. # Command format: ONBUILD INSTRUCTION
  3. # Description: nacos dockerfile
  4. # author: john chance
  5. # https://github.com/zhuchance
  6. # 基于centos7 ssh镜像
  7. FROM centos-ssh-root
  8. # 创建java home目录
  9. RUN mkdir -p /usr/lib/java/jdk1.8.0_151 \
  10. && mkdir -p /opt
  11. COPY nacos /opt/nacos
  12. COPY profile /etc
  13. # 将JDK复制到镜像中
  14. COPY jdk1.8.0_151 /usr/lib/java/jdk1.8.0_151
  15. # 配置JAVA 环境变量
  16. ENV JAVA_HOME /usr/lib/java/jdk1.8.0_151
  17. ENV PATH ${PATH}:${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin
  18. ENV CLASSPATH ${CLASSPATH}:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib
  19. # 设置编码
  20. ENV LANG en_US.UTF-8
  21. ENV LANGUAGE en_US:en
  22. ENV LC_ALL en_US.UTF-8
  23. # 映射端口
  24. EXPOSE 8848 8848
  25. # 启动tomcat
  26. CMD ["/bin/bash","/opt/nacos/bin/startup.sh"]

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/564416
推荐阅读
相关标签
  

闽ICP备14008679号