k8s创建pod

创建pod

创建pod的方式有两种
1.使用命令行进行创建
2.编辑yaml进行创建

服务状态

[root@master ~]# systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-06-28 09:00:51 CST; 37s ago
     Docs: https://docs.docker.com
 Main PID: 1009 (dockerd)
    Tasks: 15
   Memory: 114.9M
   CGroup: /system.slice/docker.service
           └─1009 /usr/bin/dockerd -H unix://


[root@master ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
   Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/kubelet.service.d
           └─10-kubeadm.conf
   Active: active (running) since Fri 2024-06-28 09:00:59 CST; 25s ago
     Docs: https://kubernetes.io/docs/
 Main PID: 1792 (kubelet)
    Tasks: 28
   Memory: 136.2M
   CGroup: /system.slice/kubelet.service
           ├─1792 /usr/bin/kubelet --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/co...
           └─2074 /opt/cni/bin/calico

docker  kubelet 启动

使用命令行进行创建pod

1.拉取镜像(用nginx实验)

#用docker拉取nginx镜像
[root@master ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest

#查看镜像
[root@master ~]# docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
nginx                                latest              605c77e624dd        2 years ago         141MB

2.创建pod

# run 运行  my-nginx 自定义pod 名称   image 引用的nginx镜像:版本
[root@master ~]# kubectl run my-nginx --image=nginx:latest

#获取一下pod的信息
[root@master ~]# kubectl get po
NAME                        READY   STATUS        RESTARTS   AGE
my-nginx-77ccc6b85f-82fzq   1/1     Running       1          16h
nginx-demo                  1/1     Running       4          27d
nginx-nvbmg                 1/1     Terminating   0          30d
nginx-t5lls                 1/1     Terminating   0          30d

 3.查看某个pod的日志

# logs pod的全称
[root@master ~]# kubectl logs my-nginx-77ccc6b85f-82fzq





/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
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/06/28 01:02:39 [notice] 1#1: using the "epoll" event method
2024/06/28 01:02:39 [notice] 1#1: nginx/1.21.5
2024/06/28 01:02:39 [notice] 1#1: built by gcc 10.2.1 20210110 (Debian 10.2.1-6) 
2024/06/28 01:02:39 [notice] 1#1: OS: Linux 3.10.0-1160.118.1.el7.x86_64
2024/06/28 01:02:39 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/06/28 01:02:39 [notice] 1#1: start worker processes
2024/06/28 01:02:39 [notice] 1#1: start worker process 30
2024/06/28 01:02:39 [notice] 1#1: start worker process 31
2024/06/28 01:02:39 [notice] 1#1: start worker process 32
2024/06/28 01:02:39 [notice] 1#1: start worker process 33

4.进入pod所创建的容器

# exec -it  
[root@master ~]# kubectl exec -it my-nginx-77ccc6b85f-82fzq -- /bin/bash
root@my-nginx-77ccc6b85f-82fzq:/# 
root@my-nginx-77ccc6b85f-82fzq:/# nginx -v
nginx version: nginx/1.21.5
root@my-nginx-77ccc6b85f-82fzq:/# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>

 # 列出pod时显示pod IP和pod的节点

[root@master ~]# kubectl get pod -o wide
NAME                        READY   STATUS        RESTARTS   AGE   IP                NODE    NOMINATED NODE   READINESS GATES
my-nginx-77ccc6b85f-82fzq   1/1     Running       1          17h   192.168.166.154   node1   <none> 

5.获取pod节点的详细信息

[root@master ~]# kubectl describe pod my-nginx-77ccc6b85f-82fzq


列出一部分内容
Events:
  Type    Reason          Age                From            Message
  ----    ------          ----               ----            -------
  Normal  SandboxChanged  42m (x2 over 42m)  kubelet, node1  Pod sandbox changed, it will be killed and re-created.
  Normal  Pulling         41m                kubelet, node1  Pulling image "nginx:latest"
  Normal  Pulled          41m                kubelet, node1  Successfully pulled image "nginx:latest"
  Normal  Created         41m                kubelet, node1  Created container my-nginx
  Normal  Started         41m                kubelet, node1  Started container my-nginx


这里是events 下面列出了拉取镜像的内容 成功拉取镜像 已经创建my-nginx容器 并启动它的过程

结束啦啦啦啦啦啦   每天记录一点 学习收获满满

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

伟大的Akk

初入茅庐小小者加油!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值