Kubernetes基础:指定容器执行时使用的参数

本文介绍了如何在Kubernetes中使用Deployment结合Service启动服务,并着重讲解如何在Deployment中指定容器启动时的参数,包括Docker参数传递的示例和不同格式的参数设置方法。
摘要由CSDN通过智能技术生成

前面的文章中介绍了使用Deployment和Service启动nginx服务的方法,为了后续继续介绍Ingress和其他功能,这里需要确定访问服务时能够返回不同的信息,这篇文章继续介绍一下如何指定容器执行时使用的参数。

使用Deployment + Service

使用Deployment和Service,能够让用户直接访问到暴露出来的服务,使用这种方式启动的nginx服务的示例如下所示:

在此基础之上,我们进行一些扩展,首先启动nginx服务并确认Pod

[root@host131 nginx]# ls
deployment.yml  service.yml
[root@host131 nginx]# kubectl create -f .
deployment.apps/nginx-deployment created
service/nginx-service created
[root@host131 nginx]# 
[root@host131 nginx]# kubectl get service nginx-service -o wide
NAME            TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE   SELECTOR
nginx-service   NodePort   10.254.131.2   <none>        80:30000/TCP   22s   app=nginx-app
[root@host131 nginx]# kubectl get pod |grep nginx
nginx-deployment-7c5b8fc568-9g4jb   1/1     Running   0          31s
[root@host131 nginx]#

进入到pod之后,修改nginx的index.html文件

[root@host131 nginx]# kubectl exec -it nginx-deployment-7c5b8fc568-9g4jb sh
/ # cd /usr/share/nginx/html/
/usr/share/nginx/html # ls
50x.html    index.html
/usr/share/nginx/html # vi index.html 
/usr/share/nginx/html # cat index.html 
<!DOCTYPE html>
<html>
<body>
<title>Welcome to use nginx</title>>

<script>
	document.write("location: " + window.location.href + "</br>");
	document.write("hostname: " + window.location.hostname 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值