首页 > 其他分享 >Kubernetes入门宝典

Kubernetes入门宝典

时间:2022-10-14 10:35:43浏览次数:102  
标签:bin compose 入门 Kubernetes 宝典 yum usr docker local

docker基础

在线安装

1、docker安装

  • centos7
 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
  • 安装yum工具包
yum install -y yum-utils
  • 设置镜像仓库
yum-config-manager \
    --add-repo \
https://download.docker.com/linux/centos/docker-ce.repo 这是国外的,安装国内的阿里云镜像

yum-config-manager \
    --add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
推荐使用用国内的
  • 更新软件包索引
yum makecache fast
  • 安装docker的相关内容
//docker-ce 社区  ee 企业版
yum install docker-ce docker-ce-cli containerd.io -y
//如果不想安装最新版本,可以安装指定版本
yum list docker-ce --showduplicates | sort -r
yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
  • 启动docker
systemctl start docker
//查看docker是否启动成功
docker version

2、阿里云的镜像加速
登录阿里云,找到镜像加速地址
阿里云镜像加速(阿里云 容器镜像服务)

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://z8wfi803.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

3、卸载docker

  • 卸载依赖
yum remove docker-ce docker-ce-cli containerd.io
  • 删除资源
rm -rf /var/lib/docker              # /var/lib/docker    docker默认的工作路径
rm -rf /var/lib/containerd

离线安装

1、环境

2、安装

  • 解压
tar -xvf docker-19.03.8.tgz
  • 移动(/user/bin/目录下)
cp docker/* /usr/bin/

  • 将docker注册为service
vim /etc/systemd/system/docker.service
#将下列配置加到docker.service中并保存
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
# BindsTo=containerd.service
# After=network-online.target firewalld.service containerd.service
After=network-online.target firewalld.service
Wants=network-online.target
# Requires=docker.socket

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not support it.
# Only systemd 226 and above support this option.
# TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

  • 启动
chmod +x /etc/systemd/system/docker.service 
systemctl daemon-reload           
systemctl start docker            
systemctl enable docker.service    
  • 验证
systemctl status docker         
docker -v                        

修改docker默认存储目录

1、环境:
centos7.x系统,已经装好docker-ce服务包

2、查看当前docker的存储路径

[root@VM-docker ~]$ docker info |grep Dir
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
         Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Docker Root Dir: /var/lib/docker              ## docker默认的存储路径

3、关闭docker服务

[root@VM-docker ~]$  systemctl stop docker            ## 关闭docker服务                            
[root@VM-docker ~]$ systemctl status docker		  ## 查看docker服务状态

4、将原有数据迁移至新目录

[root@@VM-docker local]# mkdir /data/service/docker -p
[root@@VM-docker local]# mv /var/lib/docker/* /data/docker/

5、修改docker.service配置文件,使用 --graph 参数指定存储位置

[root@VM-docker local]# vim /etc/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /data/docker

6、重新加载配置文件

[root@VM-docker local]# systemctl daemon-reload

7、启动docker服务

[root@VM-docker local]# systemctl start docker
[root@VM-docker local]# systemctl enable docker
[root@VM-docker local]# systemctl status docker

8、查看修改是否成功

[root@VM-docker ~]# docker info | grep Dir
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
WARNING: the devicemapper storage-driver is deprecated, and will be removed in a future release.
WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
         Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Docker Root Dir: /data/docker   #查看修改成功

命令自动补全

Linux

sudo curl \
    -L https://raw.githubusercontent.com/docker/compose/1.29.2/contrib/completion/bash/docker-compose \
    -o /etc/bash_completion.d/docker-compose

source ~/.bashrc

参考文档:
https://docs.docker.com/compose/completion/

搭建本地仓库

1、搭建本地仓库

mkdir /data/docker/myregistry -p
docker run -d -p 5000:5000 -v /data/docker/myregistry:/var/lib/registry registry

2、上传镜像

docker tag httpd:v11 127.0.0.1:5000/michael/httpd:v11
docker push 127.0.0.1:5000/michael/httpd:v11

3、查看 Registry 中的镜像。

#查询registry中所有的镜像名称
curl -XGET http://192.168.2.80:5000/v2/_catalog
#依据镜像名称查询镜像版本
curl -XGET http://192.168.2.80:5000/v2/httpd/tags/list

4、从 Registry 下载镜像 michael/httpd:v11

vim /etc/docker/daemon.json
{
"insecure-registries":["192.168.2.80:5000"]
}
systemctl restart docker
docker pull 192.168.2.80:5000/michael/httpd:v11

docker中centos7中文支持

1、进入docker里配置

添加中文环境编码,安装两个包
# yum install kde-l10n-Chinese -y
# yum install glibc-common -y
转化语言环境和字符集
# localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
添加定义到系统环境变量
# vi /etc/profile
export LC_ALL=zh_CN.utf8
执行生效
# source /etc/profile

2、编写dockerfile文件

FROM centos
MAINTAINER djl
#设置系统编码
RUN yum install kde-l10n-Chinese -y
RUN yum install glibc-common -y
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8
#RUN export LANG=zh_CN.UTF-8
#RUN echo "export LANG=zh_CN.UTF-8" >> /etc/locale.conf
#ENV LANG zh_CN.UTF-8
ENV LC_ALL zh_CN.UTF-8

参考文档:
https://www.lmlphp.com/user/16958/article/item/481698/

dockerfile

tomcat
#基于我们从阿里云下载下来的centos基础镜像
FROM centos
 
#定义维护者的信息
MAINTAINER kgf<[email protected]>
 
#把宿主机当前上下文的test1.txt文件拷贝到容器/usr/local/路径下
COPY readme.txt /usr/local/readme.txt
 
#把java与tomcat添加到容器中,使用ADD命令会自动帮我们解压
ADD jdk-8u191-linux-x64.tar.gz /usr/local/
ADD apache-tomcat-9.0.12.tar.gz /usr/local/
 
#安装vim编辑器
RUN yum -y install vim
 
#设置工作访问时候的workdir路径,登录落脚点
ENV MY_PATH /usr/local
WORKDIR $MY_PATH
 
#配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_191
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.12
ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.12
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
 
#容器运行时监听的端口
EXPOSE 8080
 
#启动时运行tomcat,下面的三种方式随便一种都可以使用
#ENTRYPOINT ["/usr/local/apache-tomcat-9.0.12/bin/startup.sh"]
#CMD ["/usr/local/apache-tomcat-9.0.12/bin/catalina.sh","run"]
CMD /usr/local/apache-tomcat-9.0.12/bin/startup.sh && tail -F /usr/local/apache-tomcat-9.0.12/bin/logs/catalina.out

docker-compose

安装

  • 下载
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
//国内的
sudo curl -L  https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose 
  • 修改权限
sudo chmod +x /usr/local/bin/docker-compose
  • 补全命令
curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
  • 查看是否安装成功
docker-compose version

标签:bin,compose,入门,Kubernetes,宝典,yum,usr,docker,local
From: https://www.cnblogs.com/jluo/p/16790789.html

相关文章

  • WPF 入门教程DispatcherTimer计时器
    在WinForms中,有一个名为Timer的控件,它可以在给定的时间间隔内重复执行一个操作。WPF也有这种可能性,但我们有DispatcherTimer控件,而不是不可见的控件。它几乎做同样的......
  • 540JDBC概念和541快速入门
    JDBC概念概念:java DatBaseConnectivityjava数据库连接,Java语言操作数据库JDBC本质∶其实是官方(sun公司)定义的一套操作所有关系型数据库的规则,即接口。各个数据库......
  • 子网掩码入门之简述
    什么是IP地址?人们为了通信方便给每一台计算机都事先分配一个类似电话号码一样的标识地址,即IP地址。根据TCP/IP协议,IP地址由32位二进制数组成,而且在INTERNET范围内是唯一的。......
  • 渗透测试 基础概念入门
    P1.概念名词什么是域名?域名:是由一串用点分隔的名字组成的Internet上某一台计算机或计算机组的名称,用于在数据传输时对计算机的定位标识(有时也指地理位置)。什么是二级域......
  • CentOS_Server with GUI入门
    安装模式:ServerwithGUI:基本的桌面系统,包括常用的桌面软件,如文档查看工具Minimal:基本的系统,不含有任何可选的软件包BasicServer:安装的基本系统的平台支持,不包含桌面Vi......
  • 入门学习Java必须明确的几点
    在现在对于任何人来说,学一个东西从入门到精通都是需要有一个过程的,我们才能慢慢的掌握。同样学Java也是如此,学到精通必然会得到一份高薪的工作。所以对于任何一个零基础小白......
  • LOJ 分块入门 1~9
    LOJ数列分块\(1\sim9\)T1区间加,单点查。没啥好说的,分块都不想写。树状数组+差分解决。#include<bits/stdc++.h>#definemem(a,b)memset(a,b,sizeofa)#define......
  • 多项式简陋入门
    多项式全家桶然而并没有多点求值,快速插值,转下降/上升幂,复合,复合逆疯狂多项式,v我50namespaceefX_poly{ constintmaxlen=(1<<23)+1,maxSqrt=1e5+1; inlineintad......
  • DOS出初入门学习
    打开CMD方式开始+系统+命令提示符Windows+R打开运行,输入cmd打开控制台(推荐使用)在任意位置按住Shift+鼠标右键点击,在此处打开Powershall窗口资源管理器的地址栏......
  • Salesforce入门课程,清理非活跃用户这8点必须要注意!
     非活跃用户确实给Salesforce管理员带来了诸多问题。创建用户后,可以将其设为非活跃状态,但永远不能将其删除。随着时间的推移,大多数组织的非活跃用户会远多于活跃用户。......