栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

单机版Kubernetes安装与试用

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

单机版Kubernetes安装与试用

安装Kubernetes单机版v1.21.5 一.安装Kubernetes前的一些工作
# 1.临时关闭防火墙,selinux
[root@zjs ~]# systemctl stop firewalld
[root@zjs ~]# systemctl disable firewalld
[root@zjs ~]# setenforce 0 

# 2.临时关闭swap
[root@zjs ~]# swapoff -a # 临时

# 3.传递IPv4流量给iptables链
[root@zjs ~]# cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1 
net.bridge.bridge-nf-call-iptables = 1
EOF

# 4.时间同步
[root@zjs ~]# yum install ntpdate -y
[root@zjs ~]# ntpdate time.windows.com



二.安装docker,参考前一篇swarm安装
# 1.卸载旧版本
apt-get remove docker docker-engine docker.io containerd runc
 
# 2.安装前提依赖
apt update
apt-get install ca-certificates curl gnupg lsb-release
 
# 3.安装GPG证书
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
 
# 4.写入软件源信息
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
 
# 5.安装新版本docker
apt-get install docker-ce docker-ce-cli containerd.io
 
# 6.配置用户组
groupadd docker
 
#7.启动docker
systemctl start docker
 
#8.docker换源
# 修改 /etc/docker/daemon.json (如果该文件不存在,则创建)
{
    "registry-mirrors": [
        "https://hub-mirror.c.163.com"
	]
}
 
# 9.安装必要系统工具
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
 
# 10.配置docker
# 添加 docker 配置 /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "registry-mirrors": ["docker镜像仓库国内加速"]
}
 
# 11.重启docker
service docker restart
三.Kubernetes单机版安装和使用

1.添加kubernetes的yum源

[root@zjs ~]# cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

2.  安装kubeadm,kubelet 和kubectl

[root@zjs ~]# yum -y install kubelet-1.21.5-0 kubeadm-1.21.5-0 kubectl-1.21.5-0  
[root@zjs ~]# systemctl enable kubelet

3. 部署Kubernetes Master

[root@zjs ~]# kubeadm init --apiserver-advertise-address=222.190.67.94  --image-repository registry.aliyuncs.com/google_containers  --kubernetes-version v1.21.5  --service-cidr=10.96.0.0/12  --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 222.190.67.94:6443 --token 7aj43b.lsaj1n8xg2kqhs6q 
	--discovery-token-ca-cert-hash sha256:b1ac091af23de4ecf339f7ea37973452d53e6e04a28c531bb6534032ea9b6ef7
	

参数说明:
–apiserver-advertise-address:master主机IP地址
–image-repository registry.aliyuncs.com/google_containers 这个是镜像地址
–kubernetes-version=v1.21.5 这个参数是下载的k8s软件版本号
4. 部署任务

单机版kubernetes可以先去除污点之后再部署任务

# 1.检查污点并去除
[root@zjs ~]# kubectl get node -o yaml | grep taint -A 5 
[root@zjs ~]# kubectl taint nodes --all node-role.kubernetes.io/master-  

# 2.安装补全命令的包
[root@zjs ~]# yum -y install bash-completion  
[root@zjs ~]# kubectl completion bash
[root@zjs ~]# source /usr/share/bash-completion/bash_completion
[root@zjs ~]# kubectl completion bash >/etc/profile.d/kubectl.sh
[root@zjs ~]# source /etc/profile.d/kubectl.sh
[root@zjs ~]# cat  >>  /root/.bashrc <        443/TCP        88m
service/nginx        NodePort    10.103.251.155           80:30582/TCP   26s

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/881151.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号