I created an image and pushed to dockerHub, from an angular project. I can see that if I will go to localhost:80 it will open the portal. This are the steps:
ng build
docker build -t tiberiu1234/template:v1 .
docker run -rm -d -p 80:80 tiberiu1234/template:v1
Now I tried to do the same thing but in kubernetes. I created deployment and service and trigger it using the same image:
apiVersion: apps/v1
kind: Deployment
metadata:
name: portal-deployment
labels:
app: portal
spec:
replicas: 3
selector:
matchLabels:
app: portal
template:
metadata:
labels:
app: portal
spec:
containers:
- name: portal
image: tiberiu1234/portal:v1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: portal-service
spec:
selector:
app: portal
ports:
- protocol: TCP
port: 80
targetPort: 80
Now If I will go and check I will see:
portal-deployment 0/3 3 0 4m1s
portal-service ClusterIP 10.2.0.114 <none> 80/TCP 3m56s
portal-deployment-67c6d9bb6c-88cvn 0/1 ImagePullBackOff 0 23m
portal-deployment-67c6d9bb6c-jrmjz 0/1 ImagePullBackOff 0 23m
portal-deployment-67c6d9bb6c-wm65h 0/1 ImagePullBackOff 0 23m
Error is: kubectl logs -f portal-deployment-67c6d9bb6c-88cvn Error from server (BadRequest): container "portal" in pod "portal-deployment-67c6d9bb6c-88cvn" is waiting to start: trying and failing to pull image and I don't understand why, can you help me with this?
Your repository is private and requires login to pull image.
You need to create a registry credentials secret for kubernetes, as it do not uses docker credentials.
See https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
1. Create a secret named regcred:
kubectl create secret docker-registry regcred --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-pword> --docker-email=<your-email>
2. Then use this secret in your deployment descriptor:
apiVersion: apps/v1
kind: Deployment
...
spec:
...
template:
spec:
imagePullSecrets:
- name: regcred
...