pod相关操作

[root@izuf6acp8dofkr757b6j7vz ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                  READY   STATUS    RESTARTS   AGE
kube-system   coredns-6967fb4995-cdfrb              1/1     Running   1          22h
kube-system   coredns-6967fb4995-vbcqt              1/1     Running   1          22h
kube-system   etcd-minikube                         1/1     Running   0          22h
kube-system   kube-addon-manager-minikube           1/1     Running   0          22h
kube-system   kube-apiserver-minikube               1/1     Running   0          22h
kube-system   kube-controller-manager-minikube      1/1     Running   0          22h
kube-system   kube-proxy-7brc6                      1/1     Running   0          22h
kube-system   kube-scheduler-minikube               1/1     Running   0          22h
kube-system   kubernetes-dashboard-95564f4f-9c9dv   1/1     Running   0          22h
kube-system   storage-provisioner                   1/1     Running   0          22h
[root@izuf6acp8dofkr757b6j7vz ~]# kubectl describe pod kubernetes-dashboard-95564f4f-9c9dv --namespace kube-system
Name:           kubernetes-dashboard-95564f4f-9c9dv
Namespace:      kube-system
Priority:       0
Node:           minikube/172.19.143.39
Start Time:     Sun, 03 Jan 2021 12:53:09 +0800
Labels:         addonmanager.kubernetes.io/mode=Reconcile
                app=kubernetes-dashboard
                pod-template-hash=95564f4f
                version=v1.10.1
Annotations:    <none>
Status:         Running
IP:             172.17.0.4
IPs:            <none>
Controlled By:  ReplicaSet/kubernetes-dashboard-95564f4f
Containers:
  kubernetes-dashboard:
    Container ID:  docker://88cc5505a4b8a8e5aca57c1e91ca2a25be09c942477462f9be65ce8888adc3b7
    Image:         registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
    Image ID:      docker-pullable://registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64@sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747
    Port:          9090/TCP
    Host Port:     0/TCP
    Args:
      --disable-settings-authorizer
    State:          Running
      Started:      Sun, 03 Jan 2021 12:53:10 +0800
    Ready:          True
    Restart Count:  0
    Liveness:       http-get http://:9090/ delay=30s timeout=30s period=10s #success=1 #failure=3
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-chrgh (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-chrgh:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-chrgh
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:          <none>
[root@izuf6acp8dofkr757b6j7vz home]# kubectl create -f tomcat-pod.yaml 
pod/tomcat created

创建一个pod,查看tomcat的状态处于创建中

[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                  READY   STATUS              RESTARTS   AGE
default       tomcat                                0/1     ContainerCreating   0          65s
kube-system   coredns-6967fb4995-cdfrb              1/1     Running             1          24h
kube-system   coredns-6967fb4995-vbcqt              1/1     Running             1          24h
kube-system   etcd-minikube                         1/1     Running             0          24h
kube-system   kube-addon-manager-minikube           1/1     Running             0          24h
kube-system   kube-apiserver-minikube               1/1     Running             0          24h
kube-system   kube-controller-manager-minikube      1/1     Running             0          24h
kube-system   kube-proxy-7brc6                      1/1     Running             0          24h
kube-system   kube-scheduler-minikube               1/1     Running             0          24h
kube-system   kubernetes-dashboard-95564f4f-9c9dv   1/1     Running             0          24h
kube-system   storage-provisioner   

过段时间,镜像下载完毕会自动启动容器,状态就会转为running。在控制台容器组可以看到我们创建的tomcat

[root@izuf6acp8dofkr757b6j7vz home]# kubectl describe pods/tomcat
Name:         tomcat
Namespace:    default
Priority:     0
Node:         minikube/172.19.143.39
Start Time:   Mon, 04 Jan 2021 13:47:02 +0800
Labels:       app=mytomcat
Annotations:  <none>
Status:       Running
IP:           172.17.0.5
IPs:          <none>
Containers:
  tomcat:
    Container ID:   docker://e7daac660f35930deb70b312fe09edd095eeb7a7540c6c4ee15694e7623176c8
    Image:          tomcat:8
    Image ID:       docker-pullable://tomcat@sha256:4fb2eabcae1b38add30f14a26b5a17f20ab72b40b8a12bf386d1b51f8cab4d27
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 04 Jan 2021 13:48:36 +0800
    Ready:          True
    Restart Count:  0
    Limits:
      cpu:     500m
      memory:  128Mi
    Requests:
      cpu:        500m
      memory:     128Mi
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-zg2wv (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-zg2wv:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-zg2wv
    Optional:    false
QoS Class:       Guaranteed
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type    Reason     Age    From               Message
  ----    ------     ----   ----               -------
  Normal  Scheduled  5m5s   default-scheduler  Successfully assigned default/tomcat to minikube
  Normal  Pulling    5m5s   kubelet            Pulling image "tomcat:8"
  Normal  Pulled     3m31s  kubelet            Successfully pulled image "tomcat:8"
  Normal  Created    3m31s  kubelet            Created container tomcat
  Normal  Started    3m31s  kubelet            Started container tomcat

在dashboard,可以通过运行命令进入容器

或者通过命令进入容器

[root@izuf6acp8dofkr757b6j7vz home]# kubectl exec -it tomcat -- /bin/bash
root@tomcat:/usr/local/tomcat# pwd
/usr/local/tomcat
root@tomcat:/usr/local/tomcat# ls
[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pod -o wide
NAME     READY   STATUS    RESTARTS   AGE   IP           NODE       NOMINATED NODE   READINESS GATES
tomcat   1/1     Running   0          17m   172.17.0.5   minikube   <none>           <none>
[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pods
NAME     READY   STATUS    RESTARTS   AGE
tomcat   1/1     Running   0          42m
[root@izuf6acp8dofkr757b6j7vz home]# kubectl get rs
No resources found in default namespace.
[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pods -n jenkins
No resources found in jenkins namespace.

使用-n 用来过滤名空间。删除之前部署的pod

[root@izuf6acp8dofkr757b6j7vz home]# kubectl delete pod tomcat
pod "tomcat" deleted
[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pods
No resources found in default namespace.
[root@izuf6acp8dofkr757b6j7vz home]# kubectl create -f tomcat-rs.yaml 
replicaset.apps/tomcat-rs created

创建多副本集的tomcat

[root@izuf6acp8dofkr757b6j7vz home]# kubectl get pods
NAME              READY   STATUS    RESTARTS   AGE
tomcat-rs-25x66   1/1     Running   0          72s
tomcat-rs-wvd8s   1/1     Running   0          72s
tomcat-rs-zmgb8   1/1     Running   0          72s
[root@izuf6acp8dofkr757b6j7vz home]#  kubectl get rs
NAME        DESIRED   CURRENT   READY   AGE
tomcat-rs   3         3         3       81s
[root@izuf6acp8dofkr757b6j7vz home]# kubectl create -f tomcat-service.yaml 
service/tomcat-service created

部署服务

[root@izuf6acp8dofkr757b6j7vz home]# kubectl get services
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE
kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP           25h
tomcat-service   NodePort    10.101.133.168   <none>        30000:30000/TCP   71s
[root@izuf6acp8dofkr757b6j7vz home]# kubectl describe services/tomcat-service
Name:                     tomcat-service
Namespace:                default
Labels:                   app=mytomcat
Annotations:              <none>
Selector:                 app=mytomcat
Type:                     NodePort
IP Families:              <none>
IP:                       10.101.133.168
IPs:                      <none>
Port:                     <unset>  30000/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  30000/TCP
Endpoints:                172.17.0.5:8080,172.17.0.6:8080,172.17.0.7:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>
[root@izuf6acp8dofkr757b6j7vz home]# minikube ip
! There is a newer version of minikube available (v1.16.0).  Download it here:
https://github.com/kubernetes/minikube/releases/tag/v1.16.0

To disable this notification, run the following:
minikube config set WantUpdateNotification false

172.19.143.39

这个ip其实也是阿里云虚拟机的私网ip。

[root@izuf6acp8dofkr757b6j7vz home]# kubectl get svc tomcat-service -o wide
NAME             TYPE       CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE   SELECTOR
tomcat-service   NodePort   10.101.133.168   <none>        30000:30000/TCP   12m   app=mytomcat
[root@izuf6acp8dofkr757b6j7vz home]# minikube service tomcat-service --url
http://172.19.143.39:30000

查看服务对外暴露的url地址

[root@izuf6acp8dofkr757b6j7vz home]# curl $(minikube service tomcat-service --url)
<!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:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/8.5.61</h3></body></html>[ro

或者直接用如下命令打开浏览器

t@izuf6acp8dofkr757b6j7vz home]# minikube service tomcat-service
* Opening kubernetes service default/tomcat-service in default browser...

如果需要通过外网可以用nginx再转发下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值