前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >腾讯云使用kubeadm安装k8s

腾讯云使用kubeadm安装k8s

原创
作者头像
暮雨
修改2018-11-16 11:00:43
6.9K1
修改2018-11-16 11:00:43
举报
文章被收录于专栏:云端漫步云端漫步云端漫步

k8s是现在最热门的技术之一。常混在技术圈的你,是否有种蠢蠢欲动的感觉,却因k8s环境的安装复杂性,却放弃。本篇文章将对k8s的安装进行展开。

1. 云主机环境

k8s的安装最大的障碍是网络问题,为了减少不必要的折腾,就直接选取境外境外节点的服务器。以腾讯云CVM为例。

安装以上配置开两台云主机,进行实验。

2. 基础设置

ssh 登录后,对主机进行一些基础设置

1. 设置主机名

hostnamectl set-hostname master
hostnamectl set-hostname node01

2. 设置prompt

$ vi .bashrc
host_name="k8s安装"

# Color list
green=$'\e[1;32m'
red=$'\e[1;31m'
blue=$'\e[1;34m'
cyan=$'\e[1;36m':
reset_color=$'\e[m'

PS1='\[${green}\][\u]@\[${blue}\][\h]\[${cyan}\]${host_name} ->\[${reset_color}\] \W\$'

3. host修改

vim /etc/hosts
172.31.187.45 master
172.31.187.44 node01

4. ssh免登

ssh-keygen
ssh-copy-id  node01/master

5. 关闭防火墙

systemctl stop firewalld
systemctl disable firewalld

6. 禁用SELINUX

setenforce 0
sed -i -re '/^\s*SELINUX=/s/^/#/' -e '$i\\SELINUX=disabled'  /etc/selinux/config

7. 关闭swap

swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab

8. ipv6设置

cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

3. 安装docker

yum install -y yum-utils \
           device-mapper-persistent-data \
           lvm2
yum-config-manager \
    --add-repo \
    https://mirrors.ustc.edu.cn/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce
systemctl start docker.service
systemctl enable docker.service

4. kubernetes安装

1. 添加kubernetes源

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

2. 安装kubeadm,kubelet,kubectl

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet

5. 集群安装

1. 初始化集群

kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.31.187.45

2. node节点加入集群

kubeadm join 172.31.187.45:6443 --token 8xvtce.sjvzzaqkg9dp7375 --discovery-token-ca-cert-hash sha256:03c4632898741c6e0e8d3455dfe9781cf083848c8a16e73fb72690974aa34f59

3. 设置KUBECONFIG

cp /etc/kubernetes/admin.conf $HOME/
chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf

4. flannel网络

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml

6. 查看集群信息

kubectl get nodes

# 查看集群信息
kubectl cluster-info

# 查看所有的 Pod 命令
kubectl get pods --all-namespaces

7. 测试

# 部署hello-world
kubectl run hello-world --replicas=2 --labels="run=load-balancer-example" --image=gcr.io/google-samples/node-hello:1.0  --port=8080

# 集群信息
kubectl get deployments hello-world
kubectl describe deployments hello-world

kubectl get replicasets
kubectl describe replicasets

# 创建service
kubectl expose deployment hello-world --type=NodePort --name=example-service

# 查看service
kubectl describe services example-service

kubectl get pods --selector="run=load-balancer-example" --output=wide

8. 安装dashboard

# 安装dashboard
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml

# 删除dashboard
kubectl -n kube-system delete $(kubectl -n kube-system get pod -o name | grep dashboard)

以上完成了k8s环境的安装

注意,实验完成后,为了后续的继续学习,建议将主机打为镜像,将云主机释放,在下次开始实验时,以自己构建的镜像作为模版来创建主机。祝你,操作实验顺利。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 云主机环境
  • 2. 基础设置
  • 3. 安装docker
  • 4. kubernetes安装
  • 5. 集群安装
  • 6. 查看集群信息
  • 7. 测试
  • 8. 安装dashboard
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档