1、Linux安装docker(可以跳过)
分为EE(企业版本)和CE(社区版本)
安装:https://docs.docker.com/install/linux/docker-ce/centos/
[root@promethus ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)
[root@promethus ~]# yum remove -y docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
[root@promethus ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@promethus ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@promethus ~]# ll /etc/yum.repos.d/docker-ce.repo
[root@promethus ~]# yum install docker-ce docker-ce-cli containerd.io
[root@promethus ~]# docker version
设置时区时间
[root@promethus ~]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
启动docker容器
[root@promethus ~]# systemctl start docker
[root@promethus ~]# systemctl status docker
[root@promethus ~]# docker pull nginx
Status: Downloaded newer image for nginx:latest
[root@promethus ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 27a188018e18 2 weeks ago 109MB
2、安装单机版本kubernetes
以上安装方法不适应与个人PC,会与安装kubernetes版本冲突
[root@kubernet ~]# yum install docker
[root@docker ~]# vim /etc/docker/daemon.json 配置阿里加速镜像
{ "registry-mirrors": ["***.mirror.aliyuncs.com"]}
[root@kubernet ~]# yum install -y etcd kubernetes
[root@kubernet yaml]# vim /etc/kubernetes/apiserver
编辑去掉安全和认证部分
kube-apiserver依赖于etcd(注意启动顺序)
[root@docker ~]# systemctl start etcd
[root@docker ~]# systemctl start kube-apiserver
[root@docker ~]# systemctl start kube-controller-manager
[root@docker ~]# systemctl start kube-scheduler
[root@docker ~]# netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2379 0.0.0.0:* LISTEN 5510/etcd
tcp 0 0 127.0.0.1:2380 0 .0.0.0:* LISTEN 5510/etcd
tcp 0 0 192.168.234.131:8080 0.0.0.0:* LISTEN 5530/kube-apiserver
tcp6 0 0 :::10251 :::* LISTEN 5552/kube-scheduler
tcp6 0 0 :::6443 :::* LISTEN 5530/kube-apiserver
tcp6 0 0 :::10252 :::* LISTEN 5385/kube-controlle
服务端启动完毕,下面客户端启动。
[root@docker ~]# systemctl start kubelet
[root@docker ~]# systemctl start kube-proxy
[root@docker ~]# netstat -lnpt
tcp 0 0 127.0.0.1:10248 0.0.0.0:* LISTEN 5684/kubelet
tcp 0 0 127.0.0.1:10249 0.0.0.0:* LISTEN 5742/kube-proxy
tcp 0 0 127.0.0.1:10250 0.0.0.0:* LISTEN 5684/kubelet
自此,kubernet服务全部启动完成。
3、基础命令
[root@kubernet ~]# kubectl version 确认客户端和服务器侧的版本信息
[root@kubernet ~]# kubectl api-versions 列出当前版本的kubernetes的服务器端所支持的api版本信息
[root@kubernet ~]# kubectl explain 可以和kubectl help一样进行辅助的功能确认
4、配置registry仓库
[root@promethus ~]# docker pull registry
[root@promethus ~]# docker run -d -v /opt/registry:/var/lib/registry -p 5000:5000 --restart=always --name registry registry
[root@promethus ~]# docker ps -l
[root@kubernet yaml]# curl http://192.168.19.128:5000/v2/ 首次登陆暂无镜像源
{}
[root@kubernet yaml]# curl http://192.168.19.128:5000/v2/_catalog
{"repositories":[]}
[root@promethus ~]# docker pull nginx
[root@promethus ~]# docker tag docker.io/nginx 192.168.19.128:5000/nginx:v1
[root@promethus ~]# docker images
[root@promethus ~]# cat /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"],
"insecure-registries":["192.168.19.128:5000"]
}
[root@promethus ~]# systemctl restart docker
[root@promethus ~]# docker push 192.168.19.128:5000/nginx:v1
[root@promethus ~]# docker rmi 192.168.19.128:5000/nginx:v1 docker.io/nginx
[root@promethus ~]# docker pull 192.168.19.128:5000/nginx:v1
自此registry私有参考配置完成。
5、配置第一个示例
由于不熟悉yaml文件编写,先借助命令来实现。
先配置deploy、再配合service服务。
[root@promethus yamls]# kubectl run nginx --image=nginx --replicas=2
[root@promethus yamls]# kubectl expose deployment nginx --port=80 --target-port=80 --type=NodePort
核心部分是为了以下命令,参考命令输出,编写自己的压yaml文件。
[root@promethus yamls]# kubectl edit deploy/nginx
首次部署,需要处理以下报错问题。
处理:https://www.cnblogs.com/lexiaofei/p/k8s.html
[root@promethus yamls]# yum install -y wget
[root@promethus yamls]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
[root@promethus yamls]# rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
[root@promethus yamls]# export http_proxy="http://user1:aa@aa.74.bb.5:3128"
[root@promethus yamls]# docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
[root@promethus yamls]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.19.128:5000/nginx v1 27a188018e18 2 weeks ago 109 MB
docker.io/registry latest f32a97de94e1 8 weeks ago 25.8 MB
registry.access.redhat.com/rhel7/pod-infrastructure latest 99965fb9 18 mnths ago 209 MB
[root@promethus yamls]# systemctl restart docker
部署Nginx服务。
自此,完成了第一个nginx服务。
6、配置文件说明
简单部署tomcat项目。
参考:https://www.cnblogs.com/spll/p/10075781.html
配置部署tomcat文件
[root@kubernet yaml]# vim tomcat01.yaml
注意配置各个字段的含义。