k8s集群master节点的安装
此处报错:Error from server (NotAcceptable): the server was unable to respond with a content type that the client supports (get componentstatuses)解决方法:降级kubectl客户端到与集群服务器版本相匹配的版本,这里是v1.5.2。【注】推送时harbor中需要有
k8s集群master节点的安装
环境准备
准备三台虚拟机
主机名 | 角色 |
---|---|
k8s-master | master,node |
k8s-node1 | node |
k8s-node2 | node |
harbor | harbor |
- master上需安装的服务:
etcd
apiserver
controller-manager
scheduler
kubelet
kube-proxy - node上需要安装的服务:
kubelet
kube-proxy
docker
安装etcd服务
yum install etcd -y
修改etcd的配置
vim /etc/etcd/etcd.conf
安装master节点
yum install kubernetes-master.x86_64 -y
配置apiserver
vim /etc/kubernetes/apiserver
配置controller-manager和scheduler
vim /etc/kubernetes/config
启动服务
启动apiserver服务
systemctl start kube-apiserver.service
systemctl enable kube-apiserver.service
启动controller-manager服务
systemctl start kube-controller-manager.service
systemctl enable kube-controller-manager.service
启动scheduler服务
systemctl start kube-scheduler.service
systemctl enable kube-scheduler.service
检查服务状态
kubectl get componentstatus
此处报错:Error from server (NotAcceptable): the server was unable to respond with a content type that the client supports (get componentstatuses)
出现原因:通过kubectl version --short
命令发现client和server的版本不兼容。
Client Version: v1.20.0
Server Version: v1.5.2
解决方法:降级kubectl客户端到与集群服务器版本相匹配的版本,这里是v1.5.2。可以使用以下命令来升/降级kubectl:
curl -LO "https://dl.k8s.io/release/v1.5.2/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
安装node节点
yum install kubernetes-node.x86_64 -y
修改配置
vim /etc/kubernetes/config
此处在master节点配置时已配置,此处跳过。
vim /etc/kubernetes/kubelet
启动kubelet和proxy服务
systemctl start kubelet.service
systemctl enable kubelet.service
systemctl start kube-proxy.service
systemctl enable kube-proxy.service
检查服务状态
kubectl get nodes
在所有master和node节点上部署flannel网络插件
安装flannel网络插件
yum install flannel -y
修改flannel的配置文件
vim /etc/sysconfig/flanneld
修改etcd数据库信息
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16","Backend": {"Type": "vxlan"}}'
检查etcd 中 /atomic.io/network/config 键的值
etcdctl get /atomic.io/network/config
重启服务
systemctl enable flanneld
systemctl restart flanneld
systemctl restart docker
检查fannel插件是否安装成功
修改docker的启动脚本
vim /usr/lib/systemd/system/docker.service
在[Service]区域下增加一行
ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
重新加载systemd的配置并重启Docker服务
systemctl daemon-reload && systemctl restart docker
安装docker-compose
curl -L "https://github.com/docker/compose/releases/download/v2.5.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
查看版本
docker-compose version
部署harbor镜像仓库
wget https://github.com/goharbor/harbor/releases/download/v2.3.3/harbor-offline-installer-v2.3.3.tgz
tar -zxvf harbor-offline-installer-v2.3.3.tgz
cp harbor.yml.tmpl harbor.yml
编辑harbor配置文件
vim harbor.yml
安装部署
sh install.sh
安装时出现问题:Note: docker version: 1.13.1 ✖ Need to upgrade docker package to 17.06.0+.
出现原因:harbor不支持低版本的docker
解决方法:
- 查看docker安装的软件
rpm -qa | grep docker
- 若版本过旧则删除旧版本
yum remove docker-1.13.1-210.git7d71120.el7.centos.x86_64 docker-client-1.13.1-210.git7d71120.el7.centos.x86_64 docker-common-1.13.1-210.git7d71120.el7.centos.x86_64
- 安装最新docker
curl -fsSL https://get.docker.com/ | sh
访问harbor页面
地址:http://ip:80
账号:admin
密码:Harbor12345
配置node节点镜像私有仓库地址
{
"registry-mirrors": ["https://yxzrazem.mirror.aliyuncs.com"],
"insecure-registries": ["http://192.168.92.139:80"]
}
重新加载systemd的配置并重启Docker服务
systemctl daemon-reload
systemctl restart docker
切换到harbor目录,重启harbor
cd harbor
docker-compose down -v && docker-compose up -d
重启时报错:
通过journalctl -u docker.service
查看日志
部署harbor开机自启
vim /etc/rc.local
在最后添加下述命令
cd /usr/local/harbor
docker-compose start
查看/etc/rc.local
ll /etc/rc.local
ll /etc/rc.d/rc.local
/etc/rc.d/rc.local
文件无执行权限,需添加执行权限,否则该文件无法生效
chmod +x /etc/rc.d/rc.local
重启主机验证配置的开机自启harbor的效果
reboot
harbor使用
使用docker登录harbor
docker login http://192.168.92.139:80 -u admin -p Harbor12345
登录时报错:
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error response from daemon: Get “https://192.168.92.139:80/v2/”: http: server gave HTTP response to HTTPS client
解决方法:
- 第一种:【此方法在此处未解决该问题】
- 查找 docker.service 的位置
find / -name docker.service -type f
- 修改配置文件, 在ExecStart后增加
--insecure-registry=ip
- 第二种:【此方法成功登陆】
修改docker的daemon.json配置:
tee /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"https://dockerproxy.com",
"https://ccr.ccs.tencentyun.com",
"https://registry.cn-hangzhou.aliyuncs.com"
],
"insecure-registries": ["192.168.11.20:80"]
}
EOF
重启docker服务:
systemctl restart docker
推送镜像
docker push 192.168.92.139:80/goharbor/harbor-core:v2.3.3
【注】推送时harbor中需要有对应的项目名称,否则会报错“unauthorized: project goharbor not found: project goharbor not found”。
推送后镜像仓库中会有该镜像
更多推荐
所有评论(0)