kubernetes集群搭建:
master节点安装:
1.etcd安装
apt-get install etcd
配置
service etcd restart
netstat -antp |grep etcd
2.kube-apiserver安装
配置apiserver.sh
./apiserver.sh 192.168.116.145 http://192.168.116.145:2379 --第一个参数为master地址,第二个参数为etcd地址
ps -ef |grep kube
journalctl -u kube-apiserver //实际日志存放路径 tailf /var/log/syslog
3.kube-schedule安装
配置schedule.sh
./scheduler.sh 192.168.116.145
ps -ef |grep kube
journalctl -u kube-schedule
4.kube-controller-manager安装
配置controller-manager.
./controller-manager.sh 192.168.116.145
ps -ef |grep kube
journalctl -u kube-controller-manager
netstat -antp |grep 8080
5.设置环境变量
echo "export PATH=$PATH:/opt/kubernetes/bin" >> /etc/profile
source /etc/profile
6.kube-dns 安装
kubectl create -f kubedns-cm.yaml
kubectl create -f kubedns-sa.yaml
cp kubedns-svc.yaml.sed kubedns-svc.yaml
sed -i 's/$DNS_SERVER_IP/10.10.10.2/g' kubedns-svc.yaml
kubectl create -f kubedns-svc.yaml
cp kubedns-controller.yaml.sed kubedns-controller.yaml
sed -i 's/$DNS_DOMAIN/cluster.local./g' kubedns-controller.yaml
替换image为阿里源
registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-kube-dns-amd64:1.14.10
registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.10
registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-dns-sidecar-amd64:1.14.10
添加- --kube-master-url=http://192.168.116.148:8080配置:
args:
- --domain=cluster.local
- --dns-port=10053
- --kube-master-url=http://192.168.116.148:8080
- --config-dir=/kube-dns-config
- --v=2
kubectl create -f kubedns-controller.yaml
验证dns服务:
在容器内部:curl service_name:port
查看DNS配置文件:cat /etc/resolv.conf
node节点安装:
1.kubelet安装
配置kubelet.sh
./kubelet.sh 192.168.116.145 192.168.116.146 10.10.10.2 --第一个参数为master地址,第二个参数为node地址,第三个参数为dns地址
若报错(swapoff -a),重新启动时,执行systemctl start kubelet即可
netstat -antp |grep 10250
journalctl -u kubelet
2.proxy安装
配置proxy.sh
./proxy.sh 192.168.116.145 192.168.116.146
journalctl -u kube-proxy
检查集群是否安装成功:
kubectl get nodes
kubectl describe nodes
kubectl get componentstatus #查看组件运行状态
kubectl version
kubectl cluster-info
kubernetes集群部署:
1.node节点配置加速
docker默认镜像仓库是docker hub,速度慢,改善方法:
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://04be47cf.m.daocloud.io
配置完成之后 systemctl restart docker
2.node节点
docker pull registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0
docker tag registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
3.master节点
kubectl run nginx --image=nginx --replicas=3 #创建并运行nginx镜像
kubectl get pods
kubectl describe pod nginx-7c87f569d-ccj2l #查看pod的详细信息
kubectl get all #查看所有资源
kubectl get pods -o wide #查看pod以及运行节点
4.那么如何访问nginx服务呢?
kubectl expose deployment nginx --port=88 --target-port=80 #为deployment资源暴露一个新service
kubectl get all/kubectl get services nginx #查询到nginx服务 ClusterIP=10.10.10.114
在node节点上 curl 10.10.10.114:88 即可访问nginx
kubectl get services nginx #查看service
kubectl get ep nginx #查看service的endpoints