Kubernates集群入门(1)

简介: 一、K8s安装准备 1.至少两台主机,一台作为master,一台作为node。两台主机需要关闭防火墙。 #centos6 service stop firewalld && service disable firewalld #centos7 systemctl stop iptables && systemctl disable iptables; 2.

一、K8s安装准备

1.至少两台主机,一台作为master,一台作为node。两台主机需要关闭防火墙。

#centos6 
service stop firewalld  && service disable firewalld
#centos7
systemctl stop iptables && systemctl disable iptables;

2.两台机器需要各自编辑/etc/hosts文件,互相添加hostname,然后相互ping通,以下为例

echo "192.168.18.128 centos-master
192.168.18.130 centos-minion
" >> /etc/hosts

二、K8s的安装

1.两台主机都需要安装docker,kubernetes,如有docker版本冲突需要卸载重新安装docker.

yum -y install docker kubernetes

2.master节点需要安装etcd数据库服务,etcd作为kubernetes的数据库

yum -y install etcd

3.每个节点,master及minion节点都需要修改kubernetes配置文件

vim /etc/kubernetes/config

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://centos-master:8080"
#master节点关于指向etcd的ip可能需要改成127.0.0.1:2379,改成主机名的话kube-controller-manager可能会启动失败,不知原因
KUBE_ETCD_SERVERS="--etcd_servers=http://centos-master:2379"

示例master 下config

# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
#   kube-apiserver.service
#   kube-controller-manager.service
#   kube-scheduler.service
#   kubelet.service
#   kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://kube01:8080"

KUBE_ETCD_SERVERS="--etcd-servers=http://kube01:2379"

4.master节点上,配置api服务给node

vim /etc/kubernetes/apiserver

# The address on the local server to listen to.
#这个地址好像只能用0.0.0.0
KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
# Comma separated list of nodes in the etcd cluster
#KUBE_ETCD_SERVERS="--etcd_servers=http://127.0.0.1:2379"

##ServiceAccount这个参数删掉,会影响docker拉去镜像
# default admission control policies
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"

示例:master节点apiserver:

# kubernetes system config
#
# The following values are used to configure the kube-apiserver
#

# The address on the local server to listen to.
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"

# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"

# Port minions listen on
# KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"

# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

# default admission control policies
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"

# Add your own!
KUBE_API_ARGS=""

5.master节点上编写启动相关kubernetes服务的脚本

vim k8s-server.sh

#!/bin/bash

OPT=$1

case $1 in
-s)
 for SERVICES in etcd  kube-apiserver kube-controller-manager kube-scheduler; do
        systemctl restart $SERVICES
        systemctl enable $SERVICES
        systemctl status $SERVICES
 done
;;

-k)
 for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler ; do
        systemctl stop $SERVICES
 done
;;

-stat)
 for SERVICES in etcd  kube-apiserver kube-controller-manager kube-scheduler; do
        systemctl status $SERVICES
done
;;
*)
        echo "useage:./k8s-server.sh <-s|-k|-stat>----  '-s' is start Servers\n---  '-k' is stop Servers\n'-stat' is watch the status  "
;;
esac

6.node节点修改/etc/kubernetes/kubelet,配置与master的连接

###
# kubernetes kubelet (minion) config
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname_override=centos-minion"
KUBELET_API_SERVER="--api_servers=http://centos-master:8080“
# Add your own!
KUBELET_ARGS=""

minion节点 config示例


###
# kubernetes system config
#
# The following values are used to configure various aspects of all
# kubernetes services, including
#
#   kube-apiserver.service
#   kube-controller-manager.service
#   kube-scheduler.service
#   kubelet.service
#   kube-proxy.service
# logging to stderr means we get it in the systemd journal
KUBE_LOGTOSTDERR="--logtostderr=true"

# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"

# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"

# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://kube01:8080"

minion节点kubelet示例

###
# kubernetes kubelet (minion) config

# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"

# The port for the info server to serve on
#KUBELET_PORT="--port=10250"

# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=kube02"

# location of the api-server
KUBELET_API_SERVER="--api-servers=http://kube01:8080"

# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"

# Add your own!
KUBELET_ARGS=""


7.node节点编写启动和查看服务脚本


#!/bin/bash

OPT=$1

case $1 in
-s)
 for SERVICES in kube-proxy kubelet docker; do
        systemctl restart $SERVICES
        systemctl enable $SERVICES
        systemctl status $SERVICES
 done
;;

-k)
 for SERVICES in kube-proxy kubelet docker; do
        systemctl stop $SERVICES
 done
;;

-stat)
 for SERVICES in kube-proxy kubelet docker; do
        systemctl status $SERVICES
done
;;
*)
        echo "useage:./k8s.sh <-s|-k|-stat>----  '-s' is start Servers\n---  '-k' is stop Servers\n'-stat' is watch the status  "
;;
esac

8.node节点查看是否成功注册到master节点,如果没关闭防火墙会报错

tail -f /var/log/messages |grep kube

9.master节点查看刚才注册的节点,节点status为ready为正常

kubectl get nodes

10.kubectl是master端的交互工具,可以通过子命令查看节点等信息

kubectl get nodes #获取节点列表

kubectl cluster-info #查看节点信息

下一节演示一个简单的kubernetes实例,master节点通过yaml文件,让node节点自动pull镜像并运行。**

如果启动docker报错,如下


当前docker版本1.13.1 执行启动命令: systemctl   start docker  ,报下面错误:

Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel. Either boot into a newer kernel or disable selinux in docker (--selinux-enabled=false)

重新编辑docker配置文件:
vi /etc/sysconfig/docker
# /etc/sysconfig/docker

# Modify these options if you want to change the way the docker daemon runs

OPTIONS='--selinux-enabled=false  --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
    DOCKER_CERT_PATH=/etc/docker
fi

:wq 



systemctl  restart  docker
相关实践学习
通过Ingress进行灰度发布
本场景您将运行一个简单的应用,部署一个新的应用用于新的发布,并通过Ingress能力实现灰度发布。
容器应用与集群管理
欢迎来到《容器应用与集群管理》课程,本课程是“云原生容器Clouder认证“系列中的第二阶段。课程将向您介绍与容器集群相关的概念和技术,这些概念和技术可以帮助您了解阿里云容器服务ACK/ACK Serverless的使用。同时,本课程也会向您介绍可以采取的工具、方法和可操作步骤,以帮助您了解如何基于容器服务ACK Serverless构建和管理企业级应用。 学习完本课程后,您将能够: 掌握容器集群、容器编排的基本概念 掌握Kubernetes的基础概念及核心思想 掌握阿里云容器服务ACK/ACK Serverless概念及使用方法 基于容器服务ACK Serverless搭建和管理企业级网站应用
目录
相关文章
|
7月前
|
Kubernetes Linux 应用服务中间件
Kubernetes—集群环境搭建
Kubernetes—集群环境搭建
159 0
|
存储 运维 Kubernetes
服务搭建篇(十二) Kubernetes集群的安装及部署
在所有k8s node机器执行上图第三个红框里的命令 将node节点加入进master节点的集群里,复制上图第三个红框里的命令执行(执行自己的命令)
325 0
|
1月前
|
存储 运维 Kubernetes
Kubernetes集群管理:从基础到进阶
Kubernetes集群管理:从基础到进阶
|
1月前
|
存储 Kubernetes Devops
Kubernetes集群管理和服务部署实战
Kubernetes集群管理和服务部署实战
56 0
|
3月前
|
Kubernetes 监控 Cloud Native
云原生入门:Kubernetes 集群部署与管理
【8月更文挑战第38天】在数字化浪潮中,云原生技术如同翱翔的雄鹰,引领着企业飞向灵活高效的未来。本文将带你一探究竟,从Kubernetes的基础概念到实际操作,深入浅出地介绍如何在云端构建和管理你的容器化应用。我们将一步步搭建起一个小型的Kubernetes集群,并通过代码示例和图解,让你轻松掌握云原生世界的钥匙。让我们一起开启这趟技术之旅,探索云原生的秘密花园,找到那把打开创新之门的金钥匙。
|
7月前
|
Kubernetes Cloud Native Linux
云原生|kubernetes|kubernetes集群部署神器kubekey安装部署高可用k8s集群(半离线形式)
云原生|kubernetes|kubernetes集群部署神器kubekey安装部署高可用k8s集群(半离线形式)
338 1
|
7月前
|
Kubernetes Cloud Native 应用服务中间件
云原生|kubernetes|k8s集群测试时的一些基本操作
云原生|kubernetes|k8s集群测试时的一些基本操作
145 0
|
存储 Kubernetes 应用服务中间件
使用CoreOS来部署一个Kubernetes集群,包括必要的步骤和关键概念
使用kubeadm join命令将其他CoreOS节点加入Kubernetes集群。在每个节点上运行以下命令,其中<控制平面节点IP>是Kubernetes控制平面节点的IP地址,<令牌>是在初始化控制平面时生成的令牌。
230 0
|
存储 Kubernetes Ubuntu
使用 ezctl 工具部署和管理 Kubernetes 集群
使用 ezctl 工具部署和管理 Kubernetes 集群
1268 0
使用 ezctl 工具部署和管理 Kubernetes 集群
|
存储 Kubernetes Linux
kubernetes学习-集群搭建
kubernetes学习-集群搭建
219 0