开启辅助访问 切换到窄版

Centos 7 安装配置Kubernetes容器管理系统

[复制链接]
作者:hanhongwen 
版块:
Docker容器技术 Docker容器技术-Kubernetes 发布时间:2018-8-29 01:07:27
1630

管理员

积分
6671
QQ
hanhongwen 发表于 2018-8-29 01:07:27 | 显示全部楼层 |阅读模式
1、整体架构与配置前环境准备工作

1.1 系统技术架构图
1.jpg

1.2 所有机器准备配置前置配置
  1. # yum -y install wget vim
  2. # systemctl stop firewalld && systemctl disable firewalld
  3. # sed -i "s/enforcing/disabled/g" /etc/selinux/config
  4. # sed -i '$a 192.168.8.166 master \n192.168.8.167 node1 \n192.168.8.168 node2 \n192.168.8.169 node3 \n192.168.8.170 node4' /etc/hosts
  5. # reboot
复制代码



1.3 修改系统及Docker的YUM源,并安装Docker-CE容器服务
  1. # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  2. # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

  3. # curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
  4. # systemctl daemon-reload
  5. # systemctl restart docker && systemctl enable docker
复制代码



1.4 在Master上修改Kubernetes的YUM地址,并安装Kubernetes服务
  1. # cat <<EOF > /etc/yum.repos.d/kubernetes.repo
  2. [kubernetes]
  3. name=Kubernetes
  4. baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
  5. enabled=1
  6. gpgcheck=1
  7. repo_gpgcheck=1
  8. gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
  9. EOF

  10. # yum -y install kubelet kubeadm kubectl
  11. # systemctl restart kubelet && systemctl enable kubelet
复制代码



1.5 初始Kubernetes前准备工作
  1. # sysctl net.bridge.bridge-nf-call-iptables=1
  2. # sysctl net.bridge.bridge-nf-call-ip6tables=1
  3. # echo "1" > /proc/sys/net/ipv4/ip_forward
  4. # echo "vm.swappiness = 0">> /etc/sysctl.conf
  5. # swapoff -a
  6. # sed -i 's/.*swap.*/#&/' /etc/fstab
  7. # free -m
复制代码



1.6 拉取安装Kubernetes所需要的镜像
# vim kubernetes.sh
  1. #!/bin/bash
  2. images=(kube-proxy-amd64:v1.11.2 kube-scheduler-amd64:v1.11.2 kube-controller-manager-amd64:v1.11.2 kube-apiserver-amd64:v1.11.2
  3. etcd-amd64:3.2.18 coredns:1.1.3 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.9 k8s-dns-kube-dns-amd64:1.14.9
  4. k8s-dns-dnsmasq-nanny-amd64:1.14.9 )
  5. for imageName in ${images[@]} ; do
  6. docker pull keveon/$imageName
  7. docker pull registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName
  8. docker pull registry.cn-hangzhou.aliyuncs.com/acs/$imageName
  9. docker pull registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName
  10. docker tag keveon/$imageName k8s.gcr.io/$imageName
  11. docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
  12. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
  13. docker tag registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName k8s.gcr.io/$imageName
  14. docker tag registry.cn-hangzhou.aliyuncs.com/acs/$imageName k8s.gcr.io/$imageName
  15. docker tag registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName k8s.gcr.io/$imageName
  16. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
  17. docker rmi registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName
  18. docker rmi registry.cn-hangzhou.aliyuncs.com/acs/$imageName
  19. docker rmi registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName
  20. docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
  21. docker rmi keveon/$imageName
  22. done
复制代码


# sh kubernetes.sh

1.7 初始化Kubernetes的Master,并记录最后一行内容来增加节点使用的命令
  1. # kubeadm init --kubernetes-version=1.11.2 --pod-network-cidr=172.16.0.0/16 --apiserver-advertise-address=192.168.8.166
复制代码

2.jpg

1.8 使用Root管理集群,并查看信息
  1. # export KUBECONFIG=/etc/kubernetes/admin.conf
  2. # kubectl get nodes
  3. # kubectl get pods --all-namespaces
复制代码


3.jpg

1.9 安装flanneld网络,并查看节点信息
  1. # kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
  2. # kubectl get pods --all-namespaces
复制代码


4.jpg

2、节点服务器加入集群

2.1 所有节点服务器拉取使用镜像
# vim kubernetes.sh
  1. #!/bin/bash
  2. images=(kube-proxy-amd64:v1.11.2 kube-scheduler-amd64:v1.11.2 kube-controller-manager-amd64:v1.11.2 kube-apiserver-amd64:v1.11.2
  3. etcd-amd64:3.2.18 coredns:1.1.3 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.9 k8s-dns-kube-dns-amd64:1.14.9
  4. k8s-dns-dnsmasq-nanny-amd64:1.14.9 )
  5. for imageName in ${images[@]} ; do
  6. docker pull keveon/$imageName
  7. docker pull registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName
  8. docker pull registry.cn-hangzhou.aliyuncs.com/acs/$imageName
  9. docker pull registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName
  10. docker tag keveon/$imageName k8s.gcr.io/$imageName
  11. docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
  12. docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
  13. docker tag registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName k8s.gcr.io/$imageName
  14. docker tag registry.cn-hangzhou.aliyuncs.com/acs/$imageName k8s.gcr.io/$imageName
  15. docker tag registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName k8s.gcr.io/$imageName
  16. docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
  17. docker rmi registry.cn-hangzhou.aliyuncs.com/kubernetes1112images/$imageName
  18. docker rmi registry.cn-hangzhou.aliyuncs.com/acs/$imageName
  19. docker rmi registry.cn-hangzhou.aliyuncs.com/k8s_images/$imageName
  20. docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
  21. docker rmi keveon/$imageName
  22. done
复制代码


# sh kubernetes.sh


2.2 初始化配置,并将服务器加入集群
  1. # sysctl net.bridge.bridge-nf-call-iptables=1
  2. # sysctl net.bridge.bridge-nf-call-ip6tables=1
  3. # echo "1" > /proc/sys/net/ipv4/ip_forward
  4. # echo "vm.swappiness = 0">> /etc/sysctl.conf
  5. # swapoff -a
  6. # sed -i 's/.*swap.*/#&/' /etc/fstab
  7. # free -m

  8. # yum -y install kubelet kubeadm kubectl
  9. # systemctl restart kubelet && systemctl enable kubelet


  10. kubeadm join 192.168.8.166:6443 --token ud7lks.69utwm8ju9r07pds --discovery-token-ca-cert-hash sha256:2daa4ecc12782beed1aae73e7debcf38433f7c9fb535514b37e912bf5f9cd253
复制代码


3、安装配置Dashboard

3.1 下载官方文件及相应的镜像
  1. # wget https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
  2. # docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0
  3. # docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.0
  4. # docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.0 kubernetes-dashboard
复制代码


3.2 修改配置文件内容
# vim kubernetes-dashboard.yaml
找到如下内容
  1. # ------------------- Dashboard Service ------------------- #

  2. kind: Service
  3. apiVersion: v1
  4. metadata:
  5.   labels:
  6.     k8s-app: kubernetes-dashboard
  7.   name: kubernetes-dashboard
  8.   namespace: kube-system
  9. spec:
  10.   ports:
  11.     - port: 443
  12.       targetPort: 8443
  13.   selector:
  14.     k8s-app: kubernetes-dashboard
复制代码

修改为如下内容
  1. # ------------------- Dashboard Service ------------------- #

  2. kind: Service
  3. apiVersion: v1
  4. metadata:
  5.   labels:
  6.     k8s-app: kubernetes-dashboard
  7.   name: kubernetes-dashboard
  8.   namespace: kube-system
  9. spec:
  10.   type: NodePort
  11.   ports:
  12.     - port: 443
  13.       targetPort: 8443
  14.       nodePort: 30001
  15.   selector:
  16.     k8s-app: kubernetes-dashboard
复制代码


3.3  运行如下命令配置访问问Web地址
  1. # kubectl create -f kubernetes-dashboard.yaml
  2. # kubectl apply -f kubernetes-dashboard.yaml
  3. # kubectl get pods --all-namespaces
复制代码

3.jpg

3.4 访问问Web地址
  1. https://192.168.8.166:30001
复制代码

4.jpg

3.5 获取登录令牌
  1. # kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token
复制代码

5.jpg

3.6 使用令牌登录Kubernetes
6.jpg

3.7 登录后如下图
7.jpg
    15561578755
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表