先看效果
kubectl apply -f deploy.yaml
执行上面的命令后,通过netstat -nltp 确认本机80、443是nginx进程在监听
apiVersion: v1
kind: Namespace
metadata:
name: ingress-nginx
labels:
ingress-nginx :
ingress-nginx :
---
# Source: ingress-nginx/templates/controller-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx
namespace: ingress-nginx
---
# Source: ingress-nginx/templates/controller-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx-controller
namespace: ingress-nginx
data:
---
# Source: ingress-nginx/templates/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
name: ingress-nginx
namespace: ingress-nginx
rules:
apiGroups:
''
resources:
configmaps
endpoints
nodes
pods
secrets
verbs:
list
watch
apiGroups:
''
resources:
nodes
verbs:
get
apiGroups:
''
resources:
services
verbs:
get
list
update
watch
apiGroups:
extensions
networking.k8s.io # k8s 1.14+
resources:
ingresses
verbs:
get
list
watch
apiGroups:
''
resources:
events
verbs:
create
patch
apiGroups:
extensions
networking.k8s.io # k8s 1.14+
resources:
ingresses/status
verbs:
update
apiGroups:
networking.k8s.io # k8s 1.14+
resources:
ingressclasses
verbs:
get
list
watch
---
# Source: ingress-nginx/templates/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
name: ingress-nginx
namespace: ingress-nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ingress-nginx
subjects:
kind: ServiceAccount
name: ingress-nginx
namespace: ingress-nginx
---
# Source: ingress-nginx/templates/controller-role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx
namespace: ingress-nginx
rules:
apiGroups:
''
resources:
namespaces
verbs:
get
apiGroups:
''
resources:
configmaps
pods
secrets
endpoints
verbs:
get
list
watch
apiGroups:
''
resources:
services
verbs:
get
list
update
watch
apiGroups:
extensions
networking.k8s.io # k8s 1.14+
resources:
ingresses
verbs:
get
list
watch
apiGroups:
extensions
networking.k8s.io # k8s 1.14+
resources:
ingresses/status
verbs:
update
apiGroups:
networking.k8s.io # k8s 1.14+
resources:
ingressclasses
verbs:
get
list
watch
apiGroups:
''
resources:
configmaps
resourceNames:
ingress-controller-leader-nginx
verbs:
get
update
apiGroups:
''
resources:
configmaps
verbs:
create
apiGroups:
''
resources:
endpoints
verbs:
create
get
update
apiGroups:
''
resources:
events
verbs:
create
patch
---
# Source: ingress-nginx/templates/controller-rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx
namespace: ingress-nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ingress-nginx
subjects:
kind: ServiceAccount
name: ingress-nginx
namespace: ingress-nginx
---
# Source: ingress-nginx/templates/controller-service-webhook.yaml
apiVersion: v1
kind: Service
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx-controller-admission
namespace: ingress-nginx
spec:
type: ClusterIP
ports:
name: https-webhook
port: 443
targetPort: webhook
selector:
ingress-nginx :
ingress-nginx :
controller :
---
# Source: ingress-nginx/templates/controller-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
type: LoadBalancer
externalTrafficPolicy: Local
ports:
name: http
port: 80
protocol: TCP
targetPort: http
name: https
port: 443
protocol: TCP
targetPort: https
selector:
ingress-nginx :
ingress-nginx :
controller :
---
# Source: ingress-nginx/templates/controller-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
controller :
name: ingress-nginx-controller
namespace: ingress-nginx
spec:
selector:
matchLabels:
ingress-nginx :
ingress-nginx :
controller :
revisionHistoryLimit: 10
minReadySeconds: 0
template:
metadata:
labels:
ingress-nginx :
ingress-nginx :
controller :
spec:
dnsPolicy: ClusterFirst
hostNetwork: true
nodeSelector:
app: ingress
containers:
name: controller
image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.32.0
imagePullPolicy: IfNotPresent
lifecycle:
preStop:
exec:
command:
/wait-shutdown
args:
/nginx-ingress-controller
--publish-service=ingress-nginx/ingress-nginx-controller
--election-id=ingress-controller-leader
--ingress-class=nginx
--configmap=ingress-nginx/ingress-nginx-controller
--validating-webhook=:8443
--validating-webhook-certificate=/usr/local/certificates/cert
--validating-webhook-key=/usr/local/certificates/key
securityContext:
capabilities:
drop:
ALL
add:
NET_BIND_SERVICE
runAsUser: 101
allowPrivilegeEscalation: true
env:
name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
livenessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /healthz
port: 10254
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 3
ports:
name: http
containerPort: 80
protocol: TCP
name: https
containerPort: 443
protocol: TCP
name: webhook
containerPort: 8443
protocol: TCP
volumeMounts:
name: webhook-cert
mountPath: /usr/local/certificates/
readOnly: true
resources:
requests:
cpu: 100m
memory: 90Mi
serviceAccountName: ingress-nginx
terminationGracePeriodSeconds: 300
volumes:
name: webhook-cert
secret:
secretName: ingress-nginx-admission
---
# Source: ingress-nginx/templates/admission-webhooks/validating-webhook.yaml
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingWebhookConfiguration
metadata:
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
name: ingress-nginx-admission
namespace: ingress-nginx
webhooks:
name: validate.nginx.ingress.kubernetes.io
rules:
apiGroups:
extensions
networking.k8s.io
apiVersions:
v1beta1
operations:
CREATE
UPDATE
resources:
ingresses
failurePolicy: Fail
clientConfig:
service:
namespace: ingress-nginx
name: ingress-nginx-controller-admission
path: /extensions/v1beta1/ingresses
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/clusterrole.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: ingress-nginx-admission
annotations:
pre-install,pre-upgrade,post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
rules:
apiGroups:
admissionregistration.k8s.io
resources:
validatingwebhookconfigurations
verbs:
get
update
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: ingress-nginx-admission
annotations:
pre-install,pre-upgrade,post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: ingress-nginx-admission
subjects:
kind: ServiceAccount
name: ingress-nginx-admission
namespace: ingress-nginx
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/job-createSecret.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: ingress-nginx-admission-create
annotations:
pre-install,pre-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
spec:
template:
metadata:
name: ingress-nginx-admission-create
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
spec:
containers:
name: create
image: jettech/kube-webhook-certgen:v1.2.0
imagePullPolicy: IfNotPresent
args:
create
--host=ingress-nginx-controller-admission,ingress-nginx-controller-admission.ingress-nginx.svc
--namespace=ingress-nginx
--secret-name=ingress-nginx-admission
restartPolicy: OnFailure
serviceAccountName: ingress-nginx-admission
securityContext:
runAsNonRoot: true
runAsUser: 2000
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/job-patchWebhook.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: ingress-nginx-admission-patch
annotations:
post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
spec:
template:
metadata:
name: ingress-nginx-admission-patch
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
spec:
containers:
name: patch
image: jettech/kube-webhook-certgen:v1.2.0
imagePullPolicy:
args:
patch
--webhook-name=ingress-nginx-admission
--namespace=ingress-nginx
--patch-mutating=false
--secret-name=ingress-nginx-admission
--patch-failure-policy=Fail
restartPolicy: OnFailure
serviceAccountName: ingress-nginx-admission
securityContext:
runAsNonRoot: true
runAsUser: 2000
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/role.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ingress-nginx-admission
annotations:
pre-install,pre-upgrade,post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
rules:
apiGroups:
''
resources:
secrets
verbs:
get
create
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/rolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: ingress-nginx-admission
annotations:
pre-install,pre-upgrade,post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: ingress-nginx-admission
subjects:
kind: ServiceAccount
name: ingress-nginx-admission
namespace: ingress-nginx
---
# Source: ingress-nginx/templates/admission-webhooks/job-patch/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: ingress-nginx-admission
annotations:
pre-install,pre-upgrade,post-install,post-upgrade :
before-hook-creation,hook-succeeded :
labels:
ingress-nginx-2.0.3 :
ingress-nginx :
ingress-nginx :
0.32.0 :
Helm :
admission-webhook :
namespace: ingress-nginx
tomcat-demo.yaml
执行kubectl apply -f tomcat-demo.yaml
(注意我, 这个是arm64实现成功。如果不是arm的系统,可以换成amd64的image)
apiVersion: apps/v1
kind: Deployment
metadata:
name: tomcat-demo
spec:
selector:
matchLabels:
app: tomcat-demo
replicas: 1
template:
metadata:
labels:
app: tomcat-demo
spec:
containers:
name: tomcat-demo
image: arm64v8/tomcat:9.0
ports:
containerPort: 8080
---
#service
apiVersion: v1
kind: Service
metadata:
name: tomcat-demo
spec:
ports:
port: 80
protocol: TCP
targetPort: 8080
selector:
app: tomcat-demo
---
#ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: tomcat-demo
spec:
rules:
host: tomcat.mooc.com
http:
paths:
path: /
backend:
serviceName: tomcat-demo
servicePort: 80
#有需要交流的,可以添加作者微信419644560
#备注:k3s
本文分享自微信公众号 - 架构师智库(beijing-tmt)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/4585832/blog/4405585