Ubuntu 18.04 部署 Kubernetes
-
创建虚拟机,2 核,内存 2G,磁盘 48G
-
安装系统,英文,安装 ssh 服务,机器名 ubuntu18_04
-
账户配置
# PowerShell 连接 ssh 服务 ssh-keygen -R ubuntu18_04.mshome.net ssh root@ubuntu18_04.mshome.net # 启用 root 用户 # 输入 root 用户密码 sudo passwd root # 修改登录配置,PermitRootLogin 的值改为 yes sudo vim /etc/ssh/sshd_config # 重启 ssh 服务 sudo service ssh restart
- apt 镜像源配置
# 修改 apt 镜像源 sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo vim /etc/apt/sources.list # 将以下数据添加到配置文件中 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse # 更新包 apt update & apt upgrade
- yum 安装和配置
# 安装 yum apt-get install yum # 添加 yum 源 curl -o /etc/yum/repos.d/CentOS-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo # 将 CentOS-7.repo 中的 $releasever 全部替换为 7 vim /etc/yum/repos.d/CentOS-7.repo # 安装 yum-plugin-downloadonly sudo yum install yum-plugin-downloadonly
- nginx 和 php7.2 安装
# 安装程序包 # apt install php7.2 php7.2-fpm nginx sudo apt-get install php7.2 sudo apt-get install php7.2-fpm sudo apt-get install nginx # 安装必要依赖 # apt install php-json php-curl php7.2-mysql php7.2-cgi sudo apt-get install php-json sudo apt-get install php-curl sudo apt-get install php7.2-mysql sudo apt-get install php7.2-cgi # 访问 http://ubuntu18_04.mshome.net 可看到 nginx 欢迎界面 # 配置php-frm vim /etc/php/7.2/fpm/php.ini # 773行 ;cgi.fix_fathinfo=1 更改为 cgi.fix_fathinfo=0 vim /etc/php/7.2/fpm/pool.d/www.conf # 36行 listen = 127.0.0.1:9000 # 62行 listen.allowed_clients = 127.0.0.1 # 113行 pm.max_children = 50 # 139行 pm.max_requests = 500 # 340行 request_terminate_timeout = 0 # 344行 rlimit_files = 1024 # 以上部分,包括但不限于去除前面的";" # 编写 php 测试程序 vim /var/www/html/index.php <h1> <span> hello, this is test page </span> </h1> vim /var/www/html/info.php <?php phpinfo(); ?> # 配置 nginx vim /etc/nginx/sites-available/default # 第44行,在index.html前面加入index.php # 第56-62行,用如下内容替换: location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; include fastcgi_params; } # 重启服务 sudo service php7.2-fpm restart sudo service nginx restart # 访问 http://ubuntu18_04.mshome.net 或者 http://ubuntu18_04.mshome.net/info.php
- 部署 KODExplorer
# 下载文件到 /var/www/html/KODExplorer cd /var/www/html git clone https://github.com/kalcaddle/KODExplorer.git chmod -Rf 777 ./KODExplorer/* # 指定 data 目录 cd KODExplorer vim config/define.php # 将内容替换为如下数据 <?php define('DATA_PATH',BASIC_PATH.'data/');
- 安装 docker 和 kubernetes
apt-get update && apt-get install -y apt-transport-https curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main EOF apt-get update apt-get install -y kubelet kubeadm kubectl apt install docker.io
- 配置镜像源
# 登录阿里云镜像仓库 sudo docker login --username=陈潜cloud registry.cn-hangzhou.aliyuncs.com # 添加镜像源 vim /etc/docker/daemon.json { "registry-mirrors": [ "https://7kshtxwg.mirror.aliyuncs.com", "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn", "https://cr.console.aliyun.com" ] } # 重启 docker sudo systemctl daemon-reload sudo systemctl restart docker
- 拉取镜像
# 设置主机名 hostnamectl set-hostname k8s-master # 设置环境变量 # 当前终端窗口有效 export KUBECONFIG=/etc/kubernetes/admin.conf # 永久有效 vim /etc/profile # 最后一行添加 export KUBECONFIG=/etc/kubernetes/admin.conf # 重启 reboot # 关闭 swap sudo swapoff -a free -h # 获取镜像列表 kubeadm config images list # 创建脚本 vim /var/opt/k8s_script #! /bin/bash images=( kube-apiserver:v1.18.3 kube-controller-manager:v1.18.3 kube-scheduler:v1.18.3 kube-proxy:v1.18.3 pause:3.2 etcd:3.4.3-0 coredns:1.6.7 ) for imageName in ${images[@]} ; do docker pull mirrorgcrio/$imageName docker tag mirrorgcrio/$imageName k8s.gcr.io/$imageName docker rmi mirrorgcrio/$imageName done # 执行脚本,拉取镜像 sudo chmod +x /var/opt/k8s_script /var/opt/k8s_script
- kubeadm 初始化
# kubeadm 初始化 kubeadm init # 允许 master 节点部署 pod kubectl taint nodes --all node-role.kubernetes.io/master- # 安装 cni 插件 kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml # 查看 pod 状态 watch kubectl get pods --all-namespaces
- 部署 busybox
kubectl run busybox --rm=true --image=busybox --restart=Never -it kubectl describe pod busybox
- 部署 dashboard
# Powershell 下载 yaml $src = 'https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml' $des = "recommended.yaml" Invoke-WebRequest -uri $src -OutFile $des # 部署 dashboard # kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml cp /var/www/html/KODExplorer/data/recommended.yaml recommended.yaml kubectl apply -f recommended.yaml # 配置访问权限 vim /var/opt/recommended.account.yaml apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard kubectl apply -f recommended.account.yaml # 配置角色 vim /var/opt/recommended.role.yaml apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - kind: ServiceAccount name: admin-user namespace: kubernetes-dashboard kubectl apply -f recommended.role.yaml # 外网访问 # 将集群 ClusterIP 改为 NodePort kubectl -n kubernetes-dashboard edit service kubernetes-dashboard # 查看状态 kubectl -n kubernetes-dashboard get service kubernetes-dashboard # 登录 dashboard # 访问 https://k8s-master.mshome.net:31232/ # 获取 token kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
- 安装 MySQL 8
# 添加源 wget https://repo.mysql.com//mysql-apt-config_0.8.15-1_all.deb dpkg -i mysql-apt-config_0.8.15-1_all.deb sudo apt-get update # 安装 mysql sudo apt install mysql-server # 登录 mysql,开启远程连接 mysql -uroot -p use mysql; select Host,User from user where user='root'; update user set Host='%' where User='root'; FLUSH PRIVILEGES;
- 安装 PosgreSQL 12
# 添加源 vim /etc/apt/sources.list.d/pgdg.list deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main # 导入签名 wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update # 安装 postgresql apt install postgresql-12 pgadmin4 pgadmin4-apache2 # 查看服务状态 service apache2 status # 查看端口 cat /etc/services | grep 80 # 修改端口 whereis apache2 vim /etc/apache2/ports.conf service apache2 restart # 更改密码 sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" sudo passwd postgres service postgresql restart
- 部署 NPS
# 下载并解压 wget https://github.com/ehang-io/nps/releases/download/v0.26.7/linux_amd64_server.tar.gz mkdir nps tar -xvf linux_amd64_server.tar.gz -C nps # 修改配置 vim nps/conf/nps.conf # 安装服务 cd nps ./nps install ./nps start # 查看日志 cat /var/log/nps.log
- 安装 redis
# 安装 redis apt install -y redis-server # 查看端口占用 netstat -ap | grep 6379 kill 2906 # 设置密码 vim /etc/redis/redis.conf requirepass password # 安装 redis-server /etc/redis/redis.conf
- 安装 MongoDB
# 安装 mongodb apt install -y mongodb pgrep mongo -l # 查看版本 mongo -version
- 镜像推送和拉取
# 定义标签 # docker tag 镜像ID 仓库地址:镜像名称 docker tag 4ee0e663f97d registry.cn-hangzhou.aliyuncs.com/chenqian-cloud/dev:apollo-portal # 推送镜像 # docker push 仓库地址:镜像名称 docker push registry.cn-hangzhou.aliyuncs.com/chenqian-cloud/dev:apollo-portal # 拉取镜像 # docker pull 仓库地址:镜像名称 docker pull registry.cn-hangzhou.aliyuncs.com/chenqian-cloud/dev:apollo-portal
- 替换 Deployment
kubectl replace --force -f /var/opt/k8s/wexflow.yaml
原文链接:https://blog.csdn.net/m0_54370335/article/details/115750707
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END