k8s 初体验

news/2024/11/26 11:34:08/

1.使用kubeadm工具快速安装Kubernetes集群

  • 准备工作

关掉selinux

vi /etc/selinux/config
disabled
关掉firewalld,iptables

systemctl disable firewalld
systemctl stop firewalld
systemctl disable iptables
systemctl stop iptables

编辑生成kubernetes的yum源

[root@k8s-1 network-scripts]# cat /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
修改iptables相关参数
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
安装kubeadm和相关工具
yum install kubectl kubelet kubernetes-cni kubeadm docker # 安装必要组件
systemctl enable docker.service && systemctl start docker.service 
systemctl enable kubelet.service && systemctl start kubelet.service

下载docker镜像

docker pull cloudnil/etcd-amd64:3.2.18
docker pull cloudnil/pause-amd64:3.1
docker pull cloudnil/kube-proxy-amd64:v1.11.0
docker pull cloudnil/kube-scheduler-amd64:v1.11.0
docker pull cloudnil/kube-controller-manager-amd64:v1.11.0
docker pull cloudnil/kube-apiserver-amd64:v1.11.0
docker pull cloudnil/k8s-dns-sidecar-amd64:1.14.4
docker pull cloudnil/k8s-dns-kube-dns-amd64:1.14.4
docker pull cloudnil/k8s-dns-dnsmasq-nanny-amd64:1.14.4
docker pull cloudnil/kube-discovery-amd64:1.0
docker pull cloudnil/dnsmasq-metrics-amd64:1.0
docker pull cloudnil/exechealthz-amd64:1.2
docker pull cloudnil/coredns:1.1.3
对镜像重命名
docker tag cloudnil/etcd-amd64:3.2.18    k8s.gcr.io/etcd-amd64:3.2.18
docker tag cloudnil/pause-amd64:3.1      k8s.gcr.io/pause:3.1
docker tag cloudnil/kube-proxy-amd64:v1.11.0   k8s.gcr.io/kube-proxy-amd64:v1.11.0
docker tag cloudnil/kube-scheduler-amd64:v1.11.0  k8s.gcr.io/kube-scheduler-amd64:v1.11.0
docker tag cloudnil/kube-controller-manager-amd64:v1.11.0 k8s.gcr.io/kube-controller-manager-amd64:v1.11.0
docker tag cloudnil/kube-apiserver-amd64:v1.11.0 k8s.gcr.io/kube-apiserver-amd64:v1.11.0
docker tag cloudnil/kube-discovery-amd64:1.0 k8s.gcr.io/kube-discovery-amd64:1.0
docker tag cloudnil/k8s-dns-sidecar-amd64:1.14.4 k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.4
docker tag cloudnil/k8s-dns-kube-dns-amd64:1.14.4 k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.4
docker tag cloudnil/k8s-dns-dnsmasq-nanny-amd64:1.14.4 k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.4
docker tag cloudnil/dnsmasq-metrics-amd64:1.0 k8s.gcr.io/dnsmasq-metrics-amd64:1.0
docker tag cloudnil/exechealthz-amd64:1.2 k8s.gcr.io/exechealthz-amd64:1.2
docker tag cloudnil/coredns:1.1.3   k8s.gcr.io/coredns:1.1.3

至此,准备工作已就绪,执行kubelet init 命令即可一键完成kubernetes Master节点的安装:

kubelet init --kubernetes-version=1.11.0

安装结果如下

Your Kubernetes master has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configYou 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/You can now join any number of machines by running the following on each node
as root:kubeadm join 192.168.10.208:6443 --token 4adw2b.smh6acorw0rfin3v --discovery-token-ca-cert-hash sha256:5bc323055a87fd0f6ee228e4b9d4fa58743125be0ae287ea9a26e04dbce5028e

按照提示执行完如下命令,即完成了master的安装工作

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

安装nodes节点

首先安装docker和kubeadm相关工具
yum install docker kubeadm kubelet kubectl kubernetes-cni启动docker,kubelet
systemctl enable docker.service && systemctl start docker.service
systemctl enable kubelet.service && systemctl start kubelet.service下载pause-amd64:3.1和kube-proxy-amd64:v1.11.0
docker pull cloudnil/pause-amd64:3.1
docker pull cloudnil/kube-proxy-amd64:v1.11.0
执行kubeadm join命令,加入集群
kubeadm join 192.168.10.208:6443 --token 8u66y8.uouc3e2u4hwdni3s --discovery-token-ca-cert-hash sha256:d373d424a129f5e2d2d2ba0a64bd6b9ffeca868653b4deb6bb12c5f4d3b38abd

可以看到如下的输出

you can solve this problem with following methods:1. Run 'modprobe -- ' to load missing kernel modules;
2. Provide the missing builtin kernel ipvs supportI0827 15:12:58.869512    3242 kernel_validator.go:81] Validating kernel version
I0827 15:12:58.869637    3242 kernel_validator.go:96] Validating kernel config
[discovery] Trying to connect to API Server "192.168.10.208:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://192.168.10.208:6443"
[discovery] Requesting info from "https://192.168.10.208:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "192.168.10.208:6443"
[discovery] Successfully established connection with API Server "192.168.10.208:6443"
[kubelet] Downloading configuration for the kubelet from the "kubelet-config-1.11" ConfigMap in the kube-system namespace
[kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[preflight] Activating the kubelet service
[tlsbootstrap] Waiting for the kubelet to perform the TLS Bootstrap...
[patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "node1" as an annotationThis node has joined the cluster:
* Certificate signing request was sent to master and a responsewas received.
* The Kubelet was informed of the new secure connection details.Run 'kubectl get nodes' on the master to see this node join the cluster.

安装网络插件

[cgs@master ~]$ kubectl apply -f https://git.io/weave-kube-1.6

切换到master 执行命令 kubectl get nodes

[cgs@master ~]$ kubectl get nodes
NAME      STATUS    ROLES     AGE       VERSION
master    Ready     master    33m       v1.11.2
node1     Ready     <none>    22m       v1.11.2

 


http://www.ppmy.cn/news/174850.html

相关文章

Kubernetes - 从Docker 镜像到K8s Pod操作示例

上一篇有写到怎样将一个普通的springboot的jar包&#xff0c;制作成docker镜像&#xff0c;并push到镜像仓库&#xff0c; Docker - 创建并运行一个docker&#xff08;springboot&#xff09;容器 启动这个docker容器&#xff0c;并对外提供服务等等&#xff1b; 这里我们…

离线强化学习(Offline RL)系列2: (环境篇)D4RL数据集简介、安装及错误解决

【更新日志】 Update: 2022年3月14日&#xff0c;增加D4RL安装过程报错问题。. 强化学习快速发展的主要原因在于有一个良好的模拟环境&#xff0c;最终得到一个最优的policy, 然而现实问题就是在实际落地应用中没有有效的环境&#xff0c;为了解决实验环境问题&#xff0c;本文…

CISSP-D4-通讯与网络安全

CISSP-D1-安全与风险管理 CISSP-D2-资产安全 CISSP-D3-安全架构与工程 CISSP-D5-身份与访问控制 D4&#xff1a;通讯与网络安全 一、网络模型安全概述&#xff1a; D4-1&#xff5e;2 二、网络组建和设备安全&#xff1a; D4-3&#xff5e;5 三、网络连接安全&#xff1a; …

Kubernetes基础:查看状态、管理服务

转载自https://www.cnblogs.com/cocowool/p/k8s_describe_node_pod_and_service.html 目标 了解Kubernetes Pod了解Kubernetes Node学习如何调试部署问题了解如何通过Service暴露应用 Kubernetes Pods 在Kubernetes中创建一个Deployment 部署就会在Node上创建一个Pod&#x…

k8s问题记录与解决

一、问题&#xff1a;error: open /var/lib/kubelet/config.yaml: no such file or directory 解决&#xff1a;关键文件缺失&#xff0c;多发生于没有做 kubeadm init就运行了systemctl start kubelet。 要先成功运行kubeadm init 二、kubelet.service has more than one E…

K8S的Kafka监控(Prometheus+Grafana)

对于部署在K8S上的Kafka来说&#xff0c;PrometheusGrafana是常用的监控方案&#xff0c;今天就来实战通过PrometheusGrafana监控K8S环境的Kafka&#xff1b; 准备工作 今天聚焦的是Kafka监控&#xff0c;因此需要K8S、Helm、Kafka、Prometheus、Grafana等服务都已就绪&#…

Kubernetes K8S之存储PV-PVC详解

K8S之存储PV-PVC概述与说明&#xff0c;并详解常用PV-PVC示例 概述 与管理计算实例相比&#xff0c;管理存储是一个明显的问题。PersistentVolume子系统为用户和管理员提供了一个API&#xff0c;该API从如何使用存储中抽象出如何提供存储的详细信息。为此&#xff0c;我们引入…

使用sealos快速搭建 k8s集群

k8s 集群搭建 环境信息&#xff0c;并且配置服务器互信 主机ipmaster1192.168.0.2master2192.168.0.3master3192.168.0.4node0192.168.0.5 注意事项 服务器之间必须配置互信&#xff0c;或者使用统一密码&#xff08;建议互信的方式&#xff09; 必须同步所有服务器时间 所…