1、创建Pod
apiVersion: v1
kind: Pod
metadata:
name: first-pod
labels:
app: demo
type: bash
spec:
containers:
- name: busybox-container
image: busybox
command: ['sh', '-c', 'echo Hello Kubernetes Pod! && sleep 1000']
2、查看Pod
[root@k8smaster k8s]# kubectl create -f firstpod.yaml
pod/first-pod created
[root@k8smaster k8s]# kubectl get pod
NAME READY STATUS RESTARTS AGE
first-pod 1/1 Running 0 14s
nginx-f89759699-824gr 1/1 Running 1 11d
tomcat-rs-9xkf7 1/1 Running 1 11d
tomcat-rs-k6gvk 1/1 Running 1 11d
tomcat-rs-m826x 1/1 Running 1 11d
tomcat-rs-p798l 1/1 Running 1 11d
[root@k8smaster k8s]# kubectl get pod first-pod -o yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
cni.projectcalico.org/containerID: f7a855b7e46820fca739f6f14136106dc5ee09240f0574ba685a3122c250cb05
cni.projectcalico.org/podIP: 10.244.3.15/32
cni.projectcalico.org/podIPs: 10.244.3.15/32
creationTimestamp: "2023-03-09T15:15:21Z"
labels:
app: demo
type: bash
managedFields:
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:labels:
.: {}
f:app: {}
f:type: {}
f:spec:
f:containers:
k:{"name":"busybox-container"}:
.: {}
f:command: {}
f:image: {}
f:imagePullPolicy: {}
f:name: {}
f:resources: {}
f:terminationMessagePath: {}
f:terminationMessagePolicy: {}
f:dnsPolicy: {}
f:enableServiceLinks: {}
f:restartPolicy: {}
f:schedulerName: {}
f:securityContext: {}
f:terminationGracePeriodSeconds: {}
manager: kubectl
operation: Update
time: "2023-03-09T15:15:21Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:metadata:
f:annotations:
.: {}
f:cni.projectcalico.org/containerID: {}
f:cni.projectcalico.org/podIP: {}
f:cni.projectcalico.org/podIPs: {}
manager: calico
operation: Update
time: "2023-03-09T15:15:26Z"
- apiVersion: v1
fieldsType: FieldsV1
fieldsV1:
f:status:
f:conditions:
k:{"type":"ContainersReady"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Initialized"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
k:{"type":"Ready"}:
.: {}
f:lastProbeTime: {}
f:lastTransitionTime: {}
f:status: {}
f:type: {}
f:containerStatuses: {}
f:hostIP: {}
f:phase: {}
f:podIP: {}
f:podIPs:
.: {}
k:{"ip":"10.244.3.15"}:
.: {}
f:ip: {}
f:startTime: {}
manager: kubelet
operation: Update
time: "2023-03-09T15:15:30Z"
name: first-pod
namespace: default
resourceVersion: "168254"
selfLink: /api/v1/namespaces/default/pods/first-pod
uid: c4a62166-7f23-4ee8-8623-9668016dcd75
spec:
containers:
- command:
- sh
- -c
- echo Hello Kubernetes Pod! && sleep 1000
image: busybox
imagePullPolicy: Always
name: busybox-container
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-lkdvq
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: k8node1
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: default-token-lkdvq
secret:
defaultMode: 420
secretName: default-token-lkdvq
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2023-03-09T15:15:22Z"
status: "True"
type: Initialized
- lastProbeTime: null
lastTransitionTime: "2023-03-09T15:15:30Z"
status: "True"
type: Ready
- lastProbeTime: null
lastTransitionTime: "2023-03-09T15:15:30Z"
status: "True"
type: ContainersReady
- lastProbeTime: null
lastTransitionTime: "2023-03-09T15:15:22Z"
status: "True"
type: PodScheduled
containerStatuses:
- containerID: docker://9087e974cc4368300efc06e53043bf99dd4d37e4692fd64d7039a896de613992
image: busybox:latest
imageID: docker-pullable://busybox@sha256:5acba83a746c7608ed544dc1533b87c737a0b0fb730301639a0179f9344b1678
lastState: {}
name: busybox-container
ready: true
restartCount: 0
started: true
state:
running:
startedAt: "2023-03-09T15:15:29Z"
hostIP: 192.168.56.105
phase: Running
podIP: 10.244.3.15
podIPs:
- ip: 10.244.3.15
qosClass: BestEffort
startTime: "2023-03-09T15:15:22Z"
[root@k8smaster k8s]# kubectl logs firstpod
Error from server (NotFound): pods "firstpod" not found
[root@k8smaster k8s]# kubectl logs first-pod
Hello Kubernetes Pod!
[root@k8smaster k8s]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
first-pod 1/1 Running 0 4m34s app=demo,type=bash
nginx-f89759699-824gr 1/1 Running 1 11d app=nginx,pod-template-hash=f89759699
tomcat-rs-9xkf7 1/1 Running 1 11d app=mytomcat
tomcat-rs-k6gvk 1/1 Running 1 11d app=mytomcat
tomcat-rs-m826x 1/1 Running 1 11d app=mytomcat
tomcat-rs-p798l 1/1 Running 1 11d app=mytomcat
[root@k8smaster k8s]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:14:f6:45 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 80870sec preferred_lft 80870sec
inet6 fe80::c76c:4998:8cb6:249b/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:cc:5c:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.56.104/24 brd 192.168.56.255 scope global noprefixroute dynamic enp0s8
valid_lft 321sec preferred_lft 321sec
inet6 fe80::bea2:4d55:d62c:3021/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:d2:ab:0c brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:d2:ab:0c brd ff:ff:ff:ff:ff:ff
6: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:6c:e1:85:b9 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
7: flannel.1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UNKNOWN group default
link/ether 26:ed:16:df:74:0b brd ff:ff:ff:ff:ff:ff
inet 10.244.0.0/32 scope global flannel.1
valid_lft forever preferred_lft forever
inet6 fe80::24ed:16ff:fedf:740b/64 scope link
valid_lft forever preferred_lft forever
8: cni0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP group default qlen 1000
link/ether d6:e6:c6:12:a9:24 brd ff:ff:ff:ff:ff:ff
inet 10.244.0.1/24 brd 10.244.0.255 scope global cni0
valid_lft forever preferred_lft forever
inet6 fe80::d4e6:c6ff:fe12:a924/64 scope link
valid_lft forever preferred_lft forever
9: veth0259314b@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue master cni0 state UP group default
link/ether b6:61:2f:97:35:47 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::b461:2fff:fe97:3547/64 scope link
valid_lft forever preferred_lft forever
10: calic0abcd6dfcd@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
11: tunl0@NONE: <NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN group default qlen 1000
link/ipip 0.0.0.0 brd 0.0.0.0
inet 10.244.16.128/32 scope global tunl0
valid_lft forever preferred_lft forever
12: calia8533fc65fb@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netnsid 2
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
13: cali366027b817d@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1480 qdisc noqueue state UP group default
link/ether ee:ee:ee:ee:ee:ee brd ff:ff:ff:ff:ff:ff link-netnsid 3
inet6 fe80::ecee:eeff:feee:eeee/64 scope link
valid_lft forever preferred_lft forever
[root@k8smaster k8s]#