Linux——pod实验练习

练习:

  1. 创建一个deployment资源
    • 名为test-nginx
    • 使用nginx:1.19.1版本镜像
    • 设置pod 标签为 app=frontend
    • 设置副本数量为3
  2. 创建一个service 将上面的服务暴露给客户端访问
  3. 基于nginx:1.19.1构建一个新的镜像。镜像名为mynginx:new_files
    • base镜像为nginx:1.19.1
    • 更新本地的index.html 文件到镜像的/usr/share/nginx/html 目录下
    • 本地index.html文件的内容为“update on 10-8”
    • 镜像名为mynginx:new_files
    • 如果使用docker build进行构建,注意将镜像同步到每一个工作节点上
  4. 更新test-nginx的镜像为上一步构建的mynginx:new-files
  5. 访问pod所运行的nginx服务时,获得响应为update on 10-8
  6. 结合日志,观察pod的调度和访问,重点观察滚动更新的过程
  7. [root@control ~]# source  .kube/k8s_bash_completion
    [root@control ~]# cp nginx-deployment.yml test-nginx.yml
    [root@control ~]# vim test-nginx.yml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: test-nginx
    spec:
      selector:
        matchLabels:
          app: frontend
      replicas: 3
      template:
        metadata:
          labels:
            app: frontend
        spec:
          containers:
          - name: test-nginx
            image: nginx:1.19.1
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 80
    
    [root@control ~]# kubectl apply -f test-nginx.yml
    deployment.apps/test-nginx created
    [root@control ~]# kubectl get pods
    NAME                         READY   STATUS    RESTARTS   AGE
    test-nginx-779c87479-phtjz   1/1     Running   0          31s
    test-nginx-779c87479-pssrj   1/1     Running   0          31s
    test-nginx-779c87479-xs2dg   1/1     Running   0          31s
    [root@control ~]# kubectl get deployments.apps
    NAME         READY   UP-TO-DATE   AVAILABLE   AGE
    test-nginx   3/3     3            3           57s
    [root@control ~]# kubectl expose deployment test-nginx
    service/test-nginx exposed
    [root@control ~]# kubectl get svc
    NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)   AGE
    kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP   11d
    test-nginx   ClusterIP   10.106.82.252   <none>        80/TCP    33s
    [root@control ~]# curl 10.106.82.252
    [root@control ~]# kubectl get pods
    NAME                         READY   STATUS    RESTARTS   AGE
    test-nginx-779c87479-phtjz   1/1     Running   0          5m2s
    test-nginx-779c87479-pssrj   1/1     Running   0          5m2s
    test-nginx-779c87479-xs2dg   1/1     Running   0          5m2s
    [root@control ~]# curl 10.106.82.252  // 使用svc 对应的集群IP进行服务访问
    ……省略输出,多尝试几次 观察service对于pod的负载均衡实现
    [root@control ~]# mkdir nginx-build
    [root@control ~]# cd nginx-build/
    [root@control nginx-build]# ls
    [root@control nginx-build]# echo "update on 10-8" >> index.html
    [root@control nginx-build]# vim Dockerfile
    [root@control nginx-build]# systemctl start docker
    # base镜像包括容器启动命令,故Dockerfile未规定,一个镜像必须包括一个容器启动命令
    [root@control nginx-build]# docker image history nginx:1.19.1
    IMAGE          CREATED       CREATED BY                                      SIZE      COMMENT
    08393e824c32   4 years ago   /bin/sh -c #(nop)  CMD ["nginx" "-g" "daemon…   0B
    <missing>      4 years ago   /bin/sh -c #(nop)  STOPSIGNAL SIGTERM           0B
    <missing>      4 years ago   /bin/sh -c #(nop)  EXPOSE 80                    0B
    <missing>      4 years ago   /bin/sh -c #(nop)  ENTRYPOINT [
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值