一、Rancher部署
功能 | 硬件 | 操作系統 | 主機IP | 主機名 |
---|---|---|---|---|
rancher | CPU 4,MEM 8G,DISK 100G | CentOS7.6 | 192.168.244.128 | rancher |
master | CPU 4,MEM 8G,DISK 100G | CentOS7.6 | 192.168.244.129 | master |
node1 | CPU 4,MEM 8G,DISK 100G | CentOS7.6 | 192.168.244.130 | node1 |
設置主機名稱
[root@localhost ~]# hostnamectl set-hostname XXX
XXX修改為rancher、master、node1
修改靜態ip地址
cd /etc/sysconfig/network-scripts/
cat ifcfg-ens33
TYPE="Ethernet"
PROXY_METHOD="none" BROWSER_ONLY="no" BOOTPROTO="static" #修改為static DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="d24eb2bb-0de1-44d2-882f-9bbada2ad398" DEVICE="ens33" ONBOOT="yes" IPADDR="192.168.244.128" #修改為想要訪問的固定靜態ip地址 NETMASK="255.255.255.0" #子網掩碼,固定寫法 GATEWAY="192.168.244.2" #見虛擬機NAT設置中網關IP DNS1="192.168.244.2" #cat /etc/resolv.conf
步驟一:
步驟2:
步驟3:更改適網絡配器
修改后重啟一下網絡服務即可 systemctl restart network
systemctl restart network
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.244.128 rancher 192.168.244.129 master 192.168.244.130 node
關閉firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# systemctl stop firewalld [root@localhost ~]# firewall-cmd --state not running # 關閉swap swapoff -a # 臨時 sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
SELinux
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. SELINUX=disabled # SELINUXTYPE= can take one of three values: # targeted - Targeted processes are protected, # minimum - Modification of targeted policy. Only selected processes are protected. # mls - Multi Level Security protection. SELINUXTYPE=targeted
修改完SELinux配置后,需要重新啟動系統
reboot
節點時間同步
crontab -l
顯示no crontab for root,解決辦法:
在 root 用戶下輸入 crontab -e,按ESC,然后:wq回車。
再次輸入crontab命令就行了,原因是服務器重裝完系統沒生成對應的文件,初始化一下就行。
[root@localhost ~]# crontab -l0 */1 * * * ntpdate time1.aliyun.com
安裝需要的軟件包, yum-util 提供yum-config-manager功能,另外兩個是devicemapper驅動依賴的
yum update -y
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
使用設置yum源為阿里雲,阿里雲yum源安裝要快
#sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.安裝docker
sudo yum install -y docker-ce
啟動docker
$ sudo systemctl start docker
開機啟動:
systemctl enable docker
配置鏡像加速器針對Docker客戶端版本大於 1.10.0 的用戶
您可以通過修改daemon配置文件/etc/docker/daemon.json來使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://v46187f2.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
[root@rancher ~]# docker pull rancher/rancher
運行rancher容器
[root@rancher ~]# sudo docker run --privileged -d --restart=unless-stopped -p 80:80 -p 443:443 rancher/rancher
[root@master ~]# docker pull rancher/rancher-agent:v2.5.5
[root@node ~]# docker pull rancher/rancher-agent:v2.5.5
Cluster health check failed: cluster agent is not ready
最后安裝集群時再執行開啟一般rancher-agent代理服務,再次執行上面的命令,先安裝master,再安裝node節點
YUM源准備
[aidocker@rnode2 ~]$ sudo vim /etc/yum.repos.d/k8s.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
安裝kubectl
[root@rancher ~]$ sudo yum -y install kubectl
[root@rnode1 ~]# mkdir .kube [root@rnode1 ~]# cd .kube/ [root@rnode1 .kube]# touch config
二、helm安裝
https://helm.sh/docs/intro/quickstart/
heml下載地址https://github.com/helm/helm/releases
-
-
打開包裝(
tar -zxvf helm-v3.0.0-linux-amd64.tar.gz
) -
helm
在解壓后的目錄中找到二進制文件,然后將其移至所需的目標位置(mv linux-amd64/helm /usr/local/bin/helm
)
從那里,你應該能夠運行客戶端,並 添加穩定回購: helm help
。
Tiller已經被刪除了
配置國內chart倉庫
添加存儲庫
helm repo add stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts helm repo add aliyuncs https://apphub.aliyuncs.com
helm repo update
查看配置的存儲倉庫
helm repo list
查找想要安裝的軟件程序
docker search repo 程序名
例:helm search repo nginx 查找 nginx 程序都有哪些版本的應用
安裝aliyun 的nginx :helm install nginx nginx/aliyuncs
查看訪問的 SVC 映射端口:kubectl get svc --namespace default -w nginx
訪問該 nginx 的 web 頁面:curl -I 192.168.168.11:30367
要跟蹤發布的狀態或重新讀取配置信息,可以使用 helm status +應用名
查看helm生成應用、卸載應用
helm list
查看集群中有哪些 helm 應用
helm uninstall +應用名
卸載應用
創建一個Helm Chart
helm create hello-helm
helm install rousing /root/hello-helm
helm install 部署名稱 路徑
相對路徑
helm install web hello-helm/
helm install web2 hello-helm
helm uninstall web
helm uninstall 應用名稱
刪除方式二:
http://www.mydlq.club/article/51/#wow6
helm delete web
helm install --dry-run --debug webs mychart/
helm list -n te-space-staging
helm list -n app-dev
helm install --dry-run --debug -n test-web webs webdemo/
debug調試
helm install --set image.repository="registry.aliyun.com.com/image/demo-web" --set image.tag="v1.1.0" app-web webdemo/ -n dev-test
helm uninstall demo-web -n app-dev
helm delete demo-web -n app-dev
三、Helmfile
helmfile安裝:
參考文檔:https://guoxudong.io/post/helmfile-quick-start/
1、下載安裝包:https://github.com/roboll/helmfile/releases
cd /usr/local/bin/ ln -s /home/weihu/helmfile_linux_amd64 helmfile chmod +x helmfile