一、命令终端
创建Pod
- 命令格式
kubectl run 自定义pod名字 --image=基础镜像 示例
[root@VM-4-8-centos kubernetes]
pod/my-nginx created
查看Pod
[root@VM-4-8-centos ~]
NAME READY STATUS RESTARTS AGE
my-nginx 1/1 Running 0 15s
- Pod详细信息
命令格式kubectl get pod podName -owide
[root@VM-4-8-centos ~]
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
my-nginx 1/1 Running 0 2m30s 10.244.0.9 vm-4-8-centos <none> <none>
- 执行过程描述
命令格式kubectl describe pod podName
[root@VM-4-8-centos ~]
Name: my-nginx
Namespace: default
Priority: 0
Node: vm-4-8-centos/10.0.4.8
Start Time: Sat, 26 Feb 2022 11:25:56 +0800
Labels: run=my-nginx
Annotations: <none>
...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m41s default-scheduler Successfully assigned default/my-nginx to vm-4-8-centos
Normal Pulling 3m41s kubelet Pulling image "nginx"
Normal Pulled 3m40s kubelet Successfully pulled image "nginx" in 882.15599ms
Normal Created 3m40s kubelet Created container my-nginx
Normal Started 3m40s kubelet Started container my-nginx
- 日志信息
命令格式kubectl logs podName
[root@VM-4-8-centos ~]
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
...
2022/02/26 03:25:57 [notice] 1
2022/02/26 03:25:57 [notice] 1
2022/02/26 03:25:57 [notice] 1
2022/02/26 03:25:57 [notice] 1
访问Pod中容器
通过kubectl get pod podName -owide 可以获取pod的IP地址,那么就可以访问Pod中的容器进程;
[root@VM-4-8-centos ~]
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
进入Pod内部
- 命令格式:
kubectl exec -it podName -- /bin/bash
[root@VM-4-8-centos ~]
root@my-nginx:/
root@my-nginx:/usr/share/nginx/html
bash: ll: command not found
root@my-nginx:/usr/share/nginx/html
50x.html index.html
root@my-nginx:/usr/share/nginx/html
删除Pod
- 命令格式:
kubectl delete pod Pod名称 -n 指定命名空间
[root@VM-4-8-centos kubernetes]
pod "my-nginx" deleted
配置文件yaml创建
apiVersion: v1
kind: Pod
metadata:
name: nginx01
namespace: default
labels:
run: nginx01
spec:
containers:
- name: nginx01
image: nginx
[root@VM-4-8-centos kubernetes]
- 删除配置文件创建的Pod
删除配置文件的同时,一起删除Pod
[root@VM-4-8-centos kubernetes]
二、Dashboard
创建Pod
选择在默认namespace=default中新建Pod,控制面板中选择yaml格式文件创建,内容与命令终端创建格式一样;
Pod菜单中可以查看目录 其他的操作小编就不再详细介绍了,管理图形化界面相信大家都可以搞定的~ 学习Pod的时候,大家都应该清楚,Pod是一个容器组,其中可以包含多个容器,那么我们接下来创建一个多容器的Pod;
创建多容器的Pod
新增Tomcat容器
apiVersion: v1
kind: Pod
metadata:
name: pod-demo1
namespace: default
labels:
run: pod-demo1
spec:
containers:
- name: nginx
image: nginx
- name: tomcat
image: tomcat:8.5.68
上传完之后,可以看到我们的pod已经运行
进入容器
pod目录列表每行最后三个点下拉列表中选择执行 进入操作的容器;
访问容器应用
分别访问Nginx和Tomcat; 格式podIP+容器端口
[root@VM-4-8-centos ~]
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod-demo1 2/2 Running 0 9m37s 10.244.0.11 vm-4-8-centos <none> <none>
[root@VM-4-8-centos ~]
hello nginx
[root@VM-4-8-centos ~]
<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:
|