kubernets -安装
文章目录基础环境docker 私有库安装Kubernets 安装k8s-Flannel 网络安装k8s-dns 安装k8s-UI 安装k8s 应用发布常用命令集附镜像地址k8s master 高可用(稍后)k8s etcd 集群(稍后)基础环境系统要求intel 处理器 不低于8G内存 4核CPUcentos7.4 64位 最好Minimal安装软件要求intel 处理器...
文章目录
基础环境
- 系统要求
- intel 处理器 不低于8G内存 4核CPU
- centos7.4 64位 最好Minimal安装
- 软件要求
- intel 处理器 不低于8G内存 4核CPU
- centos7.4 64位 最好Minimal安装
- 操作系统设置
- systemctl stop firewalld
- systemctl disable firewalld
- iptables -F && iptables -Z && iptables -X
- setenforce 0
- swapoff -a
- vi /etc/hosts
根据下面k8s 准备机器设置
192.168.1.32 master
192.168.1.32 etcd
192.168.1.33 node1
192.168.1.34 node2
docker 私有库安装
- docker安装
yum install docker -y
- 设置docker环境变量(镜像加速)
vi /etc/docker/deamon.json
{
"registry-mirrors": ["https://registry.docker-cn.com","http://f2d6cb40.m.daocloud.io"],
"insecure-registries": ["192.168.1.32:5000"]
}
- 启动docker
sytstemctl start docer
- 创建是私有库
docker run -d -p 5000:5000 --privileged=true -v /data/history:/data/registry registry --restart=always
- 推送
docker tag xxxx:1.0 192.168.1.32:5000/efei/xxxx:1.0
docker push 192.168.1.32:5000/efei/xxxx:1.0
Kubernets 安装
- 服务器准备
IP | 用途 |
---|---|
192.168.1.32 | master |
192.168.1.33 | node |
192.168.1.34 | node |
- 软件安装清单
IP | 用途 |
---|---|
192.168.1.32 | kube-apiserver, kubecontroller-manager,kube-scheduler,flannel,kube-dns,docker,etcd |
192.168.1.33 | kubelet, proxy,docker,flannel |
192.168.1.34 | kubelet, proxy,docker,flannel |
- 设置阿里云源
官网地址 : https://opsx.alibaba.com/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- 设置阿里kubernets源
cat <<EOF > /etc/yum.repos.d/kubernetes.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
EOF
setenforce 0
- 生效yum设置
yum clean
yum makecache
- 安装etcd
yum install etcd -y
- 配置etcd
vi /etc/etcd/etcd.conf
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.1.32:2379"
- 启动etcd
systemctl start etcd
- 检查etcd
ss -anl|grep 2379
etcdctl cluster-health
k8s-Flannel 网络安装
- 设置网络地址分配范围
etcdctl set /k8s/network/config ‘{ “Network”: “172.16.0.0/16” }’
- 安装Flannel
yum install flannel -y
注:master、node机器都要安装
- 配置config
vi /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://master:2379"
FLANNEL_ETCD_PREFIX="/k8s/network"
- 启动
systemctl start flanneld
- 注意事项
如果flannel在docker安装之后装的话需要执行下面操作
- 启动flannel之前最好清空iptables,关闭 docker服务 及docker0网卡
iptables -X && iptables -F %% iptables -z
ip link delete docker0
rm -f /run/flannel/docker
rm -f /run/flannel/subnet.env
iptables -P FORWARD ACCEPT (可以放在安装完成之后再执行)
- 重载系统配置并启动docker
systemctl daemon-reload
systemctl restart docker
- 如果已经安装了k8s话 还要重启k8s(含master、node)
<重启请查看命令集>
- 安装master
yum install kubernetes-master -y
注:这个命令会安装 kubecontroller-manager,kube-scheduler 三个程序
- 配置apiserver
vi /etc/kubernets/apiserver
KUBE_ETCD_SERVERS="--etcd-servers=http://etcd:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.244.0.0/16 --service-node-port-range=3000-65535"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,ResourceQuota"
- 配置config
vi /etc/kubernets/config
KUBE_MASTER="--master=http://master:8080"
- 启动master
systemctl start kube-apiserver
systemctl start kube-scheduler
systemctl start kube-controller-manager
- 安装node
yum install kubernetes-node -y
这个命令会安装 kubelet, proxy,docker 三个程序
- 配置config
vi /etc/kubernets/config
KUBE_MASTER="--master=http://master:8080"
- 配置kuber
vi /etc/kubernets/kuber
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=node2"
KUBELET_API_SERVER="--api-servers=http://master:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=192.168.1.32:5000/rhel7/pod-infrastructure:latest"
KUBELET_ARGS="--cluster-dns=172.16.1.3 --cluster-domain=cluster.local."
注意:镜像要提前下载并推送到私有库中, dns可以安装dns再配置
- 启动node
systemctl start kubelet
systemctl start kube-proxy
k8s-dns 安装
为了容器内部能通过service访问,才需要安装dns,
否则非必须安装
- 安装 kube-dns-rc.yaml
配置文件需要修改注意地方
- --domain=cluster.local.
- --kube-master-url = http://192.168.1.32:8080
- --cmd=nslookup kubernetes.default.svc.cluster.local. 127.0.0.1 >/dev/null
- --cmd=nslookup kubernetes.default.svc.cluster.local. 127.0.0.1:10053 >/dev/null
主要设置domain、master-url,目前不清楚doamain要不要加'.' , 我的猜想应该只要名字一致即可.
- 安装 kube-dns-svc.yaml
clusterIP: 10.244.2.2
- 测试dns
-
安装 busybox.yaml
-
进入busbox 容器
kubectl exec -i -t busybox sh
- 使用 nslookup 测试
nslookup kubernetes
也可以直接: kubectl exec busybox nslookup kubernetes-dashboard
k8s-UI 安装
- 安装 kubernetes-dashboard.yaml
配置文件需要修改注意地方
- --apiserver-host=http://192.168.1.32:8080
-
安装 kubernetes-dashboardsvc.yaml
-
访问
k8s 应用发布
以发布tomcat 测试
-
安装 my-web-rc.yaml
-
安装 my-web-svc.yaml
-
访问
http://nodeip:port/
常用命令集
服务 启动/停止/重启
start 启动 stop 停止 restart 重启
- etcd
systemctl start etcd
- master
systemctl start kube-apiserver.service
systemctl start kube-controller-manager.service
systemctl start kube-scheduler.service
- node
systemctl start kubelet.service
systemctl start kubelet-proxy.service
- flanneld
systemctl restart flanneld
- 重载系统配置
systemctl daemon-reload
systemctl restart docker
- 创建
kubectl create -f *.yaml
kubectl apply -f *.yaml
- 查看
kubectl get namespances
kubectl get deployment --all-namespaces
kubectl get pods --all-namespaces
kubectl get svc --all-namespaces
kubectl get pod -o wide --all-namespaces
kubectl get pod --namespace=“kuber-system” #指定表空间查询
kubectl describe pod --namespace=“kube-system”
kubectl describe svc --namespace=“kube-system”
kubectl -c <容器名>
kubectl logs -f -n kube-system
- 删除
kubectl delete -f *.yaml
kubectl delete svc --namespace=kube-system
kubectl delete pods --grace-period=0 --force
kubectl delete --all pods --namespace=kube-system
- cmd
kubectl exec busybox nslookup kubernetes-dashboard
kubectl exec busybox nslookup mytomcat
kubectl exec -i -t busybox /bin/bash
- docker 镜像操作
docker tag
docker push
docker pull <地址>
docker serach
docker run [查看网上文档]
- etcd
etcdctl set
etcdctl mk
etcdctl update
etcdctl rm
etcdctl rmdir
etcdctl get /k8s/network/config
etcdctl ls
- 辅助命令
ip link delete docker0
alias kube=‘kubectl’
alias kubegp=‘kubectl get pods’
alias kubegc=‘kubectl get svc’
附镜像地址
可以到阿里云镜像库搜索
docker pull registry.cn-shanghai.aliyuncs.com/hyzhou/busybox
docker pull registry.cn-hangzhou.aliyuncs.com/centos-jdk7-tomcat8/tomcat8:0.0.2
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/kubedns-amd64:1.9
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/kube-dnsmasq-amd64:1.4.1
docker pull registry.cn-hangzhou.aliyuncs.com/kube_containers/exechealthz-amd64:1.2
k8s master 高可用(稍后)
k8s etcd 集群(稍后)
更多推荐
所有评论(0)